
(vl-load-com)
;自动恢复捕捉
(defun DTU-ResetOsmode (a b)
	(setvar "osmode" 16383);捕捉参数可修改为自己的参数，参数查看命令：osmode
	(princ)
)
;lisp结束反应器
(if (not Osmode-LSPEDrct)
	(setq Osmode-LSPEDrct (vlr-lisp-reactor nil '((:vlr-lispEnded . DTU-ResetOsmode)))))
;创建下拉菜单
(defun menu1 (/ addmenu)
	(defun addMenu(lst / *acad Menus menu i j a o l x y)
  (setq *acad(vlax-get-acad-object)Menus(vlax-get-property(vlax-invoke-method(vlax-get-property *acad"MenuGroups")'item 0)'Menus))
  (if(VL-CATCH-ALL-ERROR-P(setq i -1 a(car lst)lst(cdr lst)menu(VL-CATCH-ALL-APPLY(function vlax-invoke-method)(List Menus'item a))))
    (and lst(setq menu(vlax-invoke-method Menus'add a)))
    (progn(VL-CATCH-ALL-APPLY'vlax-invoke-method(List menu 'RemoveFromMenuBar))
      (repeat(vla-get-count menu)(VL-CATCH-ALL-APPLY(function vla-delete)(list(VL-CATCH-ALL-APPLY(function vlax-invoke-method)(List menu 'item 0)))))))
  (while lst
    (setq x(car lst)lst(cdr lst))
    (if(="-"x)(vlax-invoke-method menu(function AddSeparator)(setq i(1+ i)))
      (if(listp(cadr x))
        (progn(setq l(cadr x)j -1 i(1+ i)o(vlax-invoke-method menu(function AddSubMenu)i(car x)))
          (while l
            (setq y(car l)l(cdr l))
            (if(="-"y)(vlax-invoke-method o(function AddSeparator)(setq j(1+ j)))
              (and(cadr y)(vlax-invoke-method o(function AddMenuItem)(setq j(1+ j))(car y)(cadr y))))))
        (and(cadr x)(vlax-invoke-method menu(function AddMenuItem)(setq i(1+ i))(car x)(cadr x))))))
  (or(equal(vlax-get-property menu(function OnMenuBar)):vlax-true)
     (zerop(vlax-get-property menu 'count))
     (vlax-invoke-method menu(function InsertInMenuBar)(1+(vlax-get-property(vlax-get-property *acad 'MenuBar)'count)))))
	(addMenu(list"小辉插件( &H)"
						(list"绘图制图"(list(list"圆管展开绘制<c1>""c1 ")									 
														 (list"矩型直管展开<c3>""c3 ")														 														 
														 (list"德国项目支架<c3B>""c3b ")
														 (list"方变径展开<c4>""c4 ")
														 (list"方弯头展开<c5>""c5 ")
														 (list"方弯头接变径展开<c5a>""c5a ")
														 (list"方马口展开<c6>""c6 ")                                           
														 (list"马口等径三通<c7b>""C7B ")
														 (list"方反弯展开<c8>""c8 ")
														 (list"圆弯头展开<y1>""y1 ")
														 (list"正圆台展开<y2>""y2 ")														 
														 (list"圆形软连接片法兰+立边<rlj>""rlj ")	
														 (list"厂标圆法兰<yfl>""yfl ")	
														 (list"参数圆法兰<yf>""yf ")
														 (list"厂标矩形法兰<ffl>""ffl ")
														 (list"福伊特方法兰<ff>""ff ") 
														 (list"参数矩形法兰<ffl1>""ffl1 ")))																												 
						(list"高级制图"(list(list"焊接圆形消音器""s1 ")
														 (list"圆管开方口(可携带变径)""c1a  ")
														 (list"变径三通<c7s>""C7S ")
														 (list"圆形软连接工装""rljgz ")
														 (list"圆形单叶片阀门""fm ")
														 (list"矩形单叶片手柄式阀门""fm2 ")
														 (list"抱箍绘制<未实装>""bg ")))
						"-"
						(list"功能合集A"(list(list"在直线两端打点(参数版)<tt>""tt ")
														 (list"在直线两端打点(1mm)<tt1>""tt1 ")
														 (list"标注排版矩形的上侧和左侧<dd>""dd  ")
														 (list"删除所有标注中心线层序号图层，变1mm的线为黄色<es>""es ")
														 (list"选字编号<chn>""chn ")
														 (list"自动递增编号<ss>""ss ")
														 (list"插入图库<se>""se ")
														 (list"快速标注排版框<dd>""dd ")
														 (list"快速标注矩形<dd1>""dd1 ")
														 (list"连续标注<ds>""ds ")
														 (list"框选成块<sb>""sb ")                                         
														 (list"重点尺寸加星<zd>""zd ")
														 (list"原位复制<cv>""cv ")
														 (list"调整字高<zg>""zg ")
														 (list"选择物体生成包围框<xjx>""xjx ")
                             (list"生成物体外形矩形框(宽度方向可调)<xjx1>""xjx1 ")														 
														 (list"重量计算<zl>""zl ")	
														 (list"重量计算<zl1>""zl1 ")
														 (list"打断线段<bs>""bs ")
														 (list"获取两条线的中点线<TX>""tx ") 
														 (list"悬挂端连线<sd>""sd ")
													   (list"文字对齐<dqa>""dqa ") 
														 (list"对齐板<dqb>""dqb ")
														 
														 (list"调整标注小数位数<dr>""dr ")
														 (list"将标注修改到当前样式<12>""12 ")
														 (list"将选中的文字扩大一倍<W1>""W1 ")
														 (list"将选中的文字缩小一倍<W2>""W2 ")

														 ))	
						(list"功能合集B"(list(list"批量合并打开DXF文件<xco>""xco ")
														 (list"批量打开DWG文件<xco1>""xco1 ")
														(list"编号递进<FG>""FG ")
														 (list"编号调整<FG1>""FG1 ")
														 (list"文字查重<fz>""fz ")
														 ))						
						"-"
						(list"选择工具"(list(list"选择所有文字<xz>""xz ")
														 (list"统计单行文字<textstat>""textstat ")
														 (list"选择所有点<xd>""xd  ")
														 (list"选择两个点生成打点<xs>""xs  ")
														 (list"选择所有标注<xm>""xm  ")
														 (list"格式刷文字<mz>""mz  ")
														 (list"格式刷标注<mx>""mx  ")
														 (list"调整文字高度<zg>""ZG ")
														 (list"变更标注样式M-5<11>""11  ")
														 (list"变更标注样式M-8<22>""22  ")
														 (list"变更标注样式M-10<33>""33  ")
														 (list"变更标注样式M-15<44>""44  ")
														 (list"变更图层到3中心线层<r3>""r3 ")
														 (list"变更颜色为红色<1>""1 ")
														 (list"变更颜色为黄色<2>""2 ")
														 (list"变更颜色为绿色<3>""3 ")
														 (list"变更颜色为青色<4>""4 ")
														 (list"变更颜色为蓝色<5>""5 ")
														 (list"变更颜色为粉红<6>""6 ")
														 (list"变更颜色为白色<7>""7 ")))					
 		   	"-"																																															     																			                                
						(list"打开金蝶云""jdy ")
						(list"插入当前时间""bb ")
						(list"关闭不存除当前文档的所有文档<off>""off ")
						(list"自动创建生成领料单<dte>""dte ")
						(list"排前检查<jc>""jc ")
						(list"自动排版<pb>""pb ")
						(list"自动调整<tz>""tz ")
						(list"自动生成尾料<fw>""fw ")
						(list"显示小辉插件命令工具箱<hz>""HZ ")
						(list"卸载插件菜单栏""(addMenu(list\"小辉插件(&H)\"))")					                       
					))
	(princ))
(menu1)

;基础环境设定(根据环境自动配置基础环境)
(defun SetupDrawingEnv ()
;设定绘图环境
;1、配置图层参数，检测是否有序号图层、轮廓层、中心线层，如果没有则新建这些图层
(if (not (tblsearch "layer" "序号图层"))  
(entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(70 . 0) '(6 . "continuous")'(62 . 7)
 (cons 2 "序号图层") ) ))
(if (not (tblsearch "layer" "1轮廓层"))  
(entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(70 . 0) '(6 . "continuous")'(62 . 7)
 (cons 2 "1轮廓层") ) ))
(if (not (tblsearch "layer" "3中心线层"))  
(progn(if (not (tblsearch "LTYPE" "CENTER"))  ; 如果没有center线型,则创建新线型
(entmake (list '(0 . "LTYPE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLinetypeTableRecord") (cons 2 "center") '  (3 . "Center ____ _ ____ _ ____ _ ____") 
'(70 . 0) '(73 . 2) '(40 . 15.0) '(49 . 10.0) '(74 . 0) '(49 . -5.0) '(74 . 0)  )))
;下面创建中心线层      
(entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(70 . 0) '(6 . "center")'(62 . 1)
 (cons 2 "3中心线层")'(370 . 15) ))))

;2、配置标注样式
(if (not (tblsearch "DIMSTYLE" "M-5")) (PROGN
(entmakex (list '(0 . "DIMSTYLE")'(100 . "AcDbSymbolTableRecord") '(100 . "AcDbDimStyleTableRecord") '(70 . 0) (cons 340 (tblobjname "style" "Standard"))(cons 2 "M-5") 
'(40 . 8) '(144 . 0) '(41 . 2) '(43 . 2) '(44 . 1.5) '(77 . 1)'(74 . 0) '(73 . 0) '(78 . 8) '(147 . 1.0)  '(140 . 6)  '(271 . 2) '(275 . 0)'(176 . 4)'(177 . 4)'(178 . 3) '(272 . 3)))))
(if (not (tblsearch "DIMSTYLE" "M-8")) (PROGN
(entmakex (list '(0 . "DIMSTYLE")'(100 . "AcDbSymbolTableRecord") '(100 . "AcDbDimStyleTableRecord") '(70 . 0) (cons 340 (tblobjname "style" "Standard"))(cons 2 "M-8") 
'(40 . 8) '(144 . 0) '(41 . 4) '(43 . 2) '(44 . 1.5) '(77 . 1)'(74 . 0) '(73 . 0) '(78 . 8) '(147 . 1.0)  '(140 . 10)  '(271 . 2) '(275 . 0)'(176 . 4)'(177 . 4)'(178 . 3) '(272 . 3)))))
(if (not (tblsearch "DIMSTYLE" "M-10")) (PROGN
(entmakex (list '(0 . "DIMSTYLE")'(100 . "AcDbSymbolTableRecord") '(100 . "AcDbDimStyleTableRecord") '(70 . 0) (cons 340 (tblobjname "style" "Standard"))(cons 2 "M-10") 
'(40 . 8) '(144 . 0) '(41 . 6) '(43 . 2) '(44 . 1.5) '(77 . 1)'(74 . 0) '(73 . 0) '(78 . 8) '(147 . 1.0)  '(140 . 12)  '(271 . 2) '(275 . 0)'(176 . 4)'(177 . 4)'(178 . 3) '(272 . 3)))))
(if (not (tblsearch "DIMSTYLE" "M-15")) (PROGN
(entmakex (list '(0 . "DIMSTYLE")'(100 . "AcDbSymbolTableRecord") '(100 . "AcDbDimStyleTableRecord") '(70 . 0) (cons 340 (tblobjname "style" "Standard"))(cons 2 "M-15") 
'(40 . 8) '(144 . 0) '(41 . 8) '(43 . 2) '(44 . 1.5) '(77 . 1)'(74 . 0) '(73 . 0) '(78 . 8) '(147 . 1.0)  '(140 . 20)  '(271 . 2) '(275 . 0)'(176 . 4)'(177 . 4)'(178 . 3) '(272 . 3)))))
(princ)
)
(SetupDrawingEnv)
;程序面板 HZ
(defun c:hz (/ mai_make_panel)
	(defun mai_make_panel (menulist / m n nn nnn menuname val_lst tt order_lst)
  (defun add_dclrow (dstr)
    (if  dstr
      (setq val_lst (cons dstr val_lst))
    ) ;_ 结束if
  ) ;_ 结束defun
  (add_dclrow "curbutton : button{width=10;vertical_margin=none;vertical_margin=none;}")
  (add_dclrow
    "curpanel : dialog{label=\"小辉插件汇总命令箱\";alignment=centered;vertical_margin=none;horizontal_margin=none;"
  ) ;_ 结束add_dclrow
  (add_dclrow ":row{")
  (setq  len    (apply 'max (mapcar 'length menulist))
		order_lst (apply 'append (mapcar 'cdr menulist))
		n    0
		m    0
  ) ;_ 结束setq
  (foreach nn menulist
    (add_dclrow
      (strcat " : boxed_column{label=\"" (car nn) "\";vertical_margin=none; horizontal_margin=none;")
    ) ;添加列表框
    (foreach nnn (cdr nn)
      (setq n  (1+ n)
				tt (car nnn)
				tt (if tt
						 tt
						 ""
					 ) ;_ 结束if
      ) ;_ 结束setq
      (add_dclrow (strcat " : curbutton{key=\"but" (vl-princ-to-string n) "\";label=\"" tt "\";}"))
    ) ;添加列表框中的按钮
    (repeat (- len (length nn))
      (setq m (1+ m))
      (add_dclrow (strcat " : curbutton{key=\"butno" (vl-princ-to-string m) "\";}"))
    ) ;按列补齐列表框中的按钮
    (add_dclrow "}")
  ) ;_ 结束foreach
  (add_dclrow
    "}:button{label=\"关闭\";key=\"cancel\";is_cancel=true;width=10;fixed_width=true;alignment=centered;}}"
  )
	
  (setq menuname (vl-filename-mktemp "temp_pannel.dcl"))
  (setq nn (open menuname "w"))
  (foreach n (reverse val_lst) (write-line n nn))
  (close nn)
  (setq nnn (load_dialog menuname))
  (vl-file-delete menuname)
  (if (not (new_dialog "curpanel" nnn))
    (exit)
  ) ;_ 结束if
  (setq n 0)
  (repeat m (mode_tile (strcat "butno" (vl-princ-to-string m)) 1) (setq m (1- m))) ;禁用补齐列表框中的按钮
  (foreach nn menulist
    (foreach nnn (cdr nn)
      (setq n  (1+ n)
				tt (car nnn) ;tt order_lst
				tt (if tt
						 tt
						 ""
					 ) ;_ 结束if
      ) ;_ 结束setq
      (if (= tt "")
				(mode_tile (strcat "but" (vl-princ-to-string n)) 1)
				(action_tile
					(strcat "but" (vl-princ-to-string n))
					(strcat "(done_dialog " (vl-princ-to-string n) ")")
				) ;_ 结束action_tile
      ) ;_ 结束if
    ) ;_ 结束foreach
  ) ;_ 结束foreach
  (setq nn (start_dialog))
  (unload_dialog nnn)
	
  (if (> nn 0)
    (progn (setq tt (cadr (nth (1- nn) order_lst))) ;取点击按钮的值(这个很关键)
			(if (= (eval (read (strcat "(type c:" tt ")"))) 'SUBR)
				(progn (princ "\n")
					(eval (read (strcat "(c:" tt ")")))
				) ;_ 结束progn
				(progn
					(princ "\n")
					(vla-SendCommand (vla-get-ActiveDocument(vlax-get-acad-object)) (strcat tt "\n"))
				) ;_ 结束progn
			) ;_ 结束if
    ) ;_ 结束progn
  ) ;_ 结束if
)
  (mai_make_panel
    (list
      (list "钣金展开"
				(list "圆直管展开" "c1") ;(list  按钮标签  运行的命令)
				(list "圆管开方口展开" "c1a")
				(list "方直管展开" "c3")
				(list "方变径展开" "c4")
				(list "方弯头展开" "c5")
				(list "弯头接变径展开" "c5A")
				(list "方马口展开" "c6")
				(list "底平中变变径三通展开" "c7S")
				(list "马口等径三通展开" "c7B")
				(list "方反弯展开" "c8")
				(list "正圆变径展开" "Y2")
				(list "圆法兰展开(参数版)" "YF")
				(list "圆法兰展开(厂标版)" "YFL")
				(list "方法兰展开(参数版)" "FFL1")
				(list "方法兰展开(厂标版）" "FFL")
				(list "方法兰展开(福伊特)" "FF")
				(list "圆形软连接片法兰展开" "RLJ")	
		    (list "贴边马口开洞" "C3A")		
				(list "圆弯头展开" "Y1")
				(list "焊接圆形风阀" "fm")
				(list "焊接矩形风阀" "fm2")
				
      ) ;_ 结束list
      (list "功能合集A"
    (list "自动编号" "SS")
    (list "自动改变编号" "chn")
	  
    (list "自动生成尾料" "fw")
    (list "自动创建领料单" "dte")
    (list "插入图框" "se")
    (list "快速标注排版板材" "DD")
    (list "标注矩形框" "DD1")
    (list "删除所有标注.中心线层.序号图层,变1mm的线为黄色" "es")
    (list "连续标注优化版" "DS")
    (list "调整文字高度" "ZG")
    (list "框选成块" "SB")
    (list "变更图层为“3中心线层" "R3")
    (list "板材重量计算" "ZL")
    (list "板材重量计算2" "ZL")
    (list "原位复制" "CV")
    (list "获取两条线的中点线" "TX")
    (list "生成选中物体外形最小矩形框" "XJX")
    (list "生成物体外形矩形框(宽度方向可调)" "XJX1")
    (list "统计文字内容和次数" "textstat")
    (list "打开金蝶云" "JDY")
    (list "选择两个点生成打点" "XS")
    (list "在直线两端打点(参数版)" "TT")
    (list "在直线两端打点(1mm)" "TT1")
    (list "插入当前时间" "BB")
    (list "关闭且不保存当前CAD打开的所有文档" "OFF")
    (list "选择所有标注" "xm")
    (list "选择所有文字" "XZ")
    (list "选择所有点" "xd")
    (list "打断相交图元" "BS")
		(list "格式刷字体" "MZ")
		
)
      (list "功能合集B"
    (list "设置当前环境为经典模式" "JDMS")
    (list "悬挂端连线" "SD")
    (list "文字对齐" "dqa")
    (list "对齐板" "dqb")
    (list "★重点尺寸标记" "ZD")
    (list "调整标注小数位数" "DR")
    (list "插入文字 手工下料" "WZ1")
		(list "插入文字 SUS304 1.5T" "WZ2")
		(list "插入文字 2" "WZ3")
		(list "插入文字 微连接" "WZ4")
    (list "切换标注样式 m-5" "11")
	  (list "切换标注样式 m-8" "22")
		(list "切换标注样式 m-15" "33")
    (list "将标注修改到当前样式" "12")
    (list "将选中的文字扩大一倍" "W1")
    (list "将选中的文字缩小一倍" "W2")
	  (list "编号递进" "fg")
		(list "编号参考序号递进" "fg1")
		(list "排版前检查" "jc")
		(list "自动排版" "pb")
		(list "自动调整" "tz")
				
)
			
    ) ;_ 结束list
  ) ;_ 结束mai_make_panel
  (princ)
)

;圆管一键展开 C1
(defun c:c1(/ c1 c1d0 c1d1 c1d2 c1d3 c1d4 c1d5 dcl_file dcl_id getdata1 make-dclcs pt0 re)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "钣金展开圆管:dialog"
				 "{ // start dcl"
				 "label = \"钣金展开圆管\";"
				 ":row{"
				 ":boxed_column {label = \"用户交互参数\";"			
			    ":edit_box{label=\"管件序号（S):\";key=\"d0\";}"
				  ":edit_box{label=\"圆管直径(Φ):\";key=\"d1\";}"
				  ":edit_box{label=\"圆管总长（L):\";key=\"d2\";}}"			 				 
				  ":boxed_column{"
			    ":edit_box{label=\"圆管壁厚（T):\";key=\"d3\";is_tab_stop = false;}"			
				  ":popup_list{label=\"分料尺寸（R):\";key=\"d4\";list=\"无\\n1219\\n1500\\n1250\";is_tab_stop=false;}"
          ":edit_box{label=\"总长模拟计算:\";key=\"d5\"; is_enabled = false;is_tab_stop = false;}}}"
				":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}";说明按钮
				"fixed_width=true;";固定宽度（?）
				 "alignment=left;";对齐方式（左对齐）
				 "} // end dll"  
			 ))	
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c1 (pt0 / l l1 n p1 p2 p3 p4 s s1 wz wz1)
		(setvar "cmdecho" 0) ;关闭普通命令提示信息
		(setvar "osmode"  0)  ;关闭对象捕捉状态
(setq L (* (- c1d1 c1d3) pi);计算圆的周长
			   	wz(/ c1d2 8)  ;预算序号文字的高度	 
				  wz1(/ c1d2 15)	 ;模拟辅助文字的高度				 
				 p1  (list (- (car pt0) (/ c1d2 2)) (- (cadr pt0) (/ l 2)))
				 p2  (list (car p1)(+ (cadr p1) L))
				 p3  (list (+ (car p2) c1d2) (cadr p2))
				 p4  (list (car p3)(cadr p1)))
	      (MK-line (list p1 p2 p3 p4))						
			  (dim p1 p2 2 -30) (dim p2 p3 1 30)
			 	
						(cond ((= c1d4 0)(setq s 0))
			    ((= c1d4 1)(setq s 1219))
			    ((= c1d4 2)(setq s 1500))
			    ((= c1d4 3)(setq s 1250))			
		);判断是否分料以及分料数据
		(if (/= s  0);当需要分料的情况时S
			(progn
				(setq s1(fix(/  L s)));用总长/板宽得到的整数判断是否需要分料
				(setq n 1
					    L1 L);L1为分料后所剩余的直段
				
				(while (and (> s1 0) (> C1D2 S))
					(if (and (= s1 1) (< (- L1 S) 120));120为预留的最小直缝焊长度。
					(progn 
					(MK-line1 (LIST (LIST (car p1) (+ (cadr p1) (- L 120))) (list(car p4)(+ (cadr p4) (- L 120)))))
					(text (strcat c1d0 "/2") (LIST (+ (car p1) (/ C1D2 2)) (+ (cadr p1) (- (* n (- L1 120)) (/ (- L1 120) 2)))) wz 1 1 "0")
					(dim (list(car p4)(+ (cadr p4) (* (1- n) s))) (list(car p4)(+ (cadr p4) (- L 120))) 2 300)
					(dim (list(car p4)(+ (cadr p4) (- L 120))) p3 2 300)	
					)
					(progn
					(MK-line1 (LIST (LIST (car p1)(+ (cadr p1) (* n s))) (list(car p4)(+ (cadr p4) (* n s)))))
					(text  "手工下料" (LIST (+ (car p1) (/ C1D2 2)) (+ (cadr p1) (- (* n s) (/ s 2)))) wz 7 1 "0")
					(dim (list(car p4)(+ (cadr p4) (* (1- n) s))) (list(car p4)(+ (cadr p4) (* n s))) 2 300)
						(if (= s1 1) (dim (list(car p4)(+ (cadr p4) (* n s))) p3 2 300)) 
					)	
						
					)
					(setq n (1+ n)
						    s1(1- s1)
						    L1(- L1 S))	
				)						
				(text  (strcat c1d0 "/1") (list(+ (car p1) (/ C1D2 2)) (- (cadr p3) (/ (- (cadr p3) (+ (cadr p4) (* (1- n) s))) 2))) wz 1 1 "0")
			)
		
			(text (strcat c1d0 "/1") pt0 wz 1 1 "0")
		)
	(text (strcat  "圆的外径为" (rtos c1d1)"mm""中径为"(rtos (- c1d1 c1d3))) (list (car p1)(- (cadr p1) 500)) 150 7 0 "序号图层")	
	(text (strcat  "圆的总长度为" (rtos C1D2)"mm" ) (list (car p1) (- (cadr p1)  700)) 150 7 0 "序号图层")
	(text (strcat  "圆的厚度为" (rtos C1D3)"t") (list (car p1) (- (cadr p1)  900)) 150 7 0 "序号图层")			
	(IF (and (< c1d1 250)(> C1D2 1200)) (text "口径低于250，卷圆长度超过1200，无法卷圆，需纵向分割" (list (car p1) (- (cadr p1)  1100)) 150 2 0 "序号图层"))
	(IF (and (>= c1d1 250)(> C1D2 1800)) (text "卷圆宽度超过1800，小卷圆机无法卷圆" (list (car p1) (- (cadr p1)  1300)) 150 2 0 "序号图层"))
	(IF (> C1D2 4000) (text "卷圆长度超过4000，无法上直缝焊机" (list (car p1) (- (cadr p1)  1500)) 150 2 0 "序号图层"))
	(IF (and (>= c1d3 4)(>= C1D2 1200)) (text "卷圆厚度超过4mm，长度超过1200，建议与下料组确认能否卷圆" (list (car p1) (- (cadr p1)  1700)) 150 2 0 "序号图层"))
		(setvar "osmode" 16383)  ;打开对象捕捉状态	
	)
	;;---------开始写面板调用函数
	(if (/= 'str (type c1d0))
      (progn (setq c1d0 "1")
      (setq c1d1 600)(setq c1d2 1500)(setq c1d3 1.5)
			(setq c1d4 0)(setq c1d5 0)
			))	
	(h-read1  "c1");读取注册表的数据
	(defun getdata1() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
 (setq 
    c1d0 (get_tile "d0")
    c1d1 (atof (get_tile "d1"))
    c1d2 (atof (get_tile "d2"))
    c1d3 (atof (get_tile "d3"))
	  c1d4 (atoi (get_tile "d4"))
 ))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "钣金展开圆管" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	(set_tile "d0" c1d0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos c1d1 2 2));
  (set_tile "d2" (rtos c1d2 2 2));
  (set_tile "d3" (rtos c1d3 2 2));
	(if (/= c1d4 nil)(set_tile "d4" (rtos c1d4 2)))
	(set_tile "d5" (rtos (* (- c1d1 c1d3) pi) 2 2 ))
  (mode_tile "d0" 2)
(action_tile "d1"  "(set_TILE \"d5\" (rtos (* (- (atof $value) c1d3) pi) 2 2))")
;当用户与 d1 控件交互（例如输入文本或点击按钮）时，执行后续代码
(action_tile "d3"  "(set_TILE \"d5\" (rtos (* (- c1d1 (atof $value)) pi) 2 2))")
	
 (action_tile "accept" "(getdata1)(done_dialog 1)") ;当按下确认按钮的时候保存控件值，然后退出界面,并执行对于功能函数
  (action_tile "cancel" "(getdata1)(done_dialog 0)") ;当按下取消按钮的时候保存控件值，然后退出界面
	(action_tile "help" "(getdata1)(done_dialog 2)")
  (setq re (start_dialog))
  (unload_dialog dcl_id)
(cond ((= re 0) ;鼠标按下确认后，开始执行这里的操作
		(progn
      (prompt"\n 用户取消绘制展开圆管！"))) ;鼠标按下确认后，将各个控件的值汇总到这里，传递给功能函数，执行功能操作	
		((= re 2) ;鼠标按下确认后，开始执行这里的操作
		(progn
      (ALERT
"暂定"     
			)))
		((= re 1)
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint "请选择图形插入点"))
				(c1 pt0)
				
			))	
	)	
	
	(h-save1  '(c1d0 c1d1 c1d2 c1d3 c1d4 c1d5 ) "c1");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;圆管开方口 C1A 
;圆管开方口 C1A 
(defun c:c1a(/ c1a c1ad0 c1ad1 c1ad10 c1ad11 c1ad12 c1ad2 c1ad3 c1ad4 c1ad5 c1ad6 c1ad7 c1ad8 c1ad9 dcl_file dcl_id getdata1 ljx-read-excel-data1 ljx-read-excel-text1 ljx-vlxls-get-range-value1 make-dclcs pt0 re test1 y2)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;面板的界面显示dcl
		(setq lst_str
			'(
				 "圆管开方口展开:dialog"
				 "{ // start dcl"
				 "label = \"圆管开方口展开\";"
         ":row{"		 
				 ":column{:edit_box{label=\"管 件 序 号  (S):\";key=\"d0\";}";编辑框
				 "        :edit_box{label=\"管 件 直 径  (D):\";key=\"d1\";}";编辑框
				 "        :edit_box{label=\"管 件 长 度  (H):\";key=\"d2\";}";编辑框
				 "        :edit_box{label=\"支 管 长 度  (L):\";key=\"d3\";}";编辑框
				 "        :edit_box{label=\"支 管 宽 度  (W):\";key=\"d4\";}";编辑框
				 "        :edit_box{label=\"支 管 高 度  (H):\";key=\"d5\";}";编辑框
				 "        :edit_box{label=\"嵌  入  量   (H):\";key=\"d6\";}}";编辑框
				 "        :column{:edit_box{label=\"板 材 厚 度  (T):\";key=\"d7\";is_tab_stop=false;}";编辑框
				 "        :popup_list{label=\"分 料 尺 寸  (R):\"  ;key=\"d8\";list=\"1219\\n1500\\n1250\";is_tab_stop=false;}"
				 "        :popup_list{label=\"携 带 变 径  (B):\"  ;key=\"d9\";list=\"不带\\n带\";is_tab_stop=false;}"
				 "        :popup_list{label=\"变 径 工 艺  (A):\"  ;key=\"d10\";list=\"焊接\\n翻遍12\\n翻遍15\";is_tab_stop=false;}"
				 "        :edit_box{label=\"大 口 直 径  (D):\";key=\"d11\";is_tab_stop=false;}";编辑框
				 "        :popup_list{label=\"变径对齐方式 (C):\"  ;key=\"d12\";list=\"4等分\\n法兰平行\";is_tab_stop=false;}"	
				 "        :button  {label=\"读取数据批量生成\"; key = \"EL1\";is_tab_stop=false;}}}"
			   

				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		;is_enabled = false;
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	;圆管开方口
 (defun c1a (pt0 / d1 fl h1 h2 h3 l l1 l2 l3 n p1 p10 p11 p12 p13 p14 p15 p2 p3 p4 p5 p6 p7 p8 p9 r s1)
				;这里填充绘制图形的代码
	  (setq d1  (- c1ad1 c1ad7);获取圆的中径	
					r  (/ d1 2);获取圆的半径
		      L(* d1 pi);获取圆的周长	
					h1 (sqrt (- (* r r) (* (* c1ad4 0.5) (* c1ad4 0.5))));勾股定理计算过方圆相交点做延长线与圆心相交的长度
					h2  (- r h1);R减去长度得到相交点到圆心象限点的距离
				  h3 (* (* (atan (/ (* c1ad4 0.5) h1)) 2.0) r));反正切三角函数求得圆弧展开长
	   (cond             ;传导分料参数
			 ((= c1ad8 0)
				(setq FL 1219));传导分料1219
			 ((= c1ad8 1)  
				(setq FL 1500));传导分料1500
			 ((= c1ad8 2)
				(setq FL 1250));传导分料1250
			 )
(setq    p1 (list (- (car pt0) (/ c1ad2 2)) (- (cadr pt0) (/ l 2)))
		     p2 (list (car p1) (+ (cadr p1) L))
		     P3 (list (+ (car p1) c1ad2) (cadr p2))
		     P4 (list (car p3) (cadr p1)))
		   (MK-line (list p1 p2 p3 p4 ));绘制圆的展开矩形框
			 (dim p1 p2 2 -100)	(dim p2 p3 1 100);标注圆的展开长宽

				(setq s1(fix(/  L fl)));用总长/板宽得到的整数初步筛选分料大概分几段
				(setq n 1  ;N为预估循环函数
					    L1 L ;L1为设置下面分料后所剩余的直段
				      L2 120;L2为预留最小直缝焊接边
	  			    )
		(while (and (> s1 0) (> C1aD2 fl));设置循环条件,同时满足初步分几段和总长小与分料板宽才会分料
			
					 (if (and (= s1 1) (< (- L1 fl) L2));设置假设条件,同时满足分料分1段,且分料减去段数的长度小于120(120为预留的最小直缝焊接边)
						   (progn  								 
							 (MK-line1 (list (list (car p1) (+ (cadr p1) L2)) (list(car p4)(+ (cadr p4) L2))));绘制分割线
							 (setq p5  (list (- (car p4) c1ad6) (+ (cadr p4) L2  (/ (- L L2 (* (- n 1) fl))2) (/ h3 2))));获取开口定位第一点
							 (MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (- (car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口
							 (dim p4 (list(car p4)(+ (cadr p4) 120)) 2 300) 
							 (dim (list(car p4)(+ (cadr p4) 120))  (list(car p3)(- (cadr p3) (* (- n 1) fl))) 2 300);标注分料线到展开线的距离
							 (dim p5 (list (- (car p5) c1ad3 2) (cadr p5))  1 50)	(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸
							 (dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2))) 1 50);标注马口到边的距离 
							 (line1 (list (car p4) (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2))) 2);绘制打标点
							 (line1 (list(car p1) (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2))) 1);绘制打标点
							 (IF (= c1ad12 1);当图纸要求平行时
								 (if (or (= c1ad9 0) (= c1ad11 0))
									   (progn (line1 (list (car p4) (+ (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 2)
											      (line1 (list (car p4) (- (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 2)
											      (line1 (list (car p1) (+ (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 1)
											      (line1 (list (car p1) (- (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 1))	
									 
								     (progn (line1 (list (car p4) (+ (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 2);绘制打标点1
									          (line1 (list (car p4) (- (+ (cadr p4) L2 (/ (- L L2 (* (- n 1) fl))2)) (/ L 8))   ) 2);绘制打标点2
									     ))) 							 
							 (text (strcat c1ad0 "/1") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ L2 2))) 150 1 1  "0");加编号1
							 (text (strcat c1ad0 "/2") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ L2 2)  (/ (- L (* (- n 1) fl) (/ L2 2)) 2)   )) 150 1 1  "0");加编号2 
							 	 
								)
							 (progn							
							 (if (/= s1 1)     ;设置假设条件,当S1不等于1时,继续分料								 						
							 (progn  
							 (MK-line1 (LIST (LIST (car p2)(- (cadr p2) (* n fl))) (list(car p3)(- (cadr p3) (* n fl)))))	 
							 (text  "手工下料" (LIST (+ (car p2) (/ c1ad2 2)) (- (cadr p2) (- (* n fl) (/ fl 2)))) 300 7 1 "0")	 
							 (dim (list(car p3)(- (cadr p3) (* (1- n) fl))) (list(car p3)(- (cadr p3) (* n fl))) 2 300))
	             (progn;当S1等于1时,再设立假设条件
								(if (= c1ad12 1);当法兰为等分时		
				        (progn 
									(setq l3 (/ l 8))
								(if	(and (> (- L1 fl) (+ h3 100)) (> (- L1 fl) (+ (* l3 2 ) 80)));当剩余长度大于板宽+弧长+100且还大于1/4的总长+80预留调整位置的长度时候,代表还可以进行一次手工下料	
								 (progn	
		             (MK-line1 (LIST (LIST (car p2)(- (cadr p2) (* n fl))) (list(car p3)(- (cadr p3) (* n fl)))));绘制手工下料分割线	 
							   (text  "手工下料" (LIST (+ (car p2) (/ c1ad2 2)) (- (cadr p2) (- (* n fl) (/ fl 2)))) 300 7 1 "0")	;编写手工下料文字
							   (dim (list(car p3)(- (cadr p3) (* (1- n) fl))) (list(car p3)(- (cadr p3) (* n fl))) 2 300);绘制手工下料尺寸
								 ;上面三行为手工下料代码,继续一次手工下料,下面开始开口
								(if (= n 2);当N=2时,且经过两次手工下料,这个时候需要调整开口位置避免重缝
								(progn
								(setq p5 (list (- (car p4) c1ad6) (+ (cadr p4)  (/ (- L (* n fl) (* l3 2)) 4) (/ (- L (* n fl)) 2) (/ h3 2))));获取开口定位第一点
								(line1  (list (car p3) (+ (cadr p4) (/ (- L (* n fl) (* l3 2)) 4) (/ (- L (* n fl)) 2) )) 2)
								(line1 (list(car p2) (+ (cadr p1) (/ (- L (* n fl) (* l3 2)) 4) (/ (- L (* n fl)) 2) )) 1);绘制打标点		
								)	
							  (progn
								(setq p5 (list (- (car p4) c1ad6) (+ (cadr p4) (/ (- L (* n fl)) 2) (/ h3 2))));获取开口定位第一点
								(line1  (list (car p3) (+ (cadr p4) (/ (- L (* n fl)) 2) )) 2)
								(line1  (list (car p2) (+ (cadr p1) (/ (- L (* n fl)) 2) )) 1)	
								))								 
								 (MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口
								 (dim p5  (list (- (car p5) c1ad3 2) (cadr p5))  1 50)(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸
								 (dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (+ (cadr p4) (/ (- L (* n fl)) 2))) 1 50);标注马口到边的距离
                (if (or (= c1ad9 0) (= c1ad11 0))
									   (progn (line1 (list (car p3) (- (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 2)
											      (line1 (list (car p3) (+ (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 2)
											      (line1 (list (car p1) (- (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 1)
											      (line1 (list (car p1) (+ (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 1))											  																			 
								     (progn (line1 (list (car p3) (- (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 2);绘制打标点1	
									          (line1 (list (car p3) (+ (+ (cadr p4) (/ (- L (* n fl)) 2) ) (/ L 8))) 2);绘制打标点2	
									     ))
                 (dim    (list(car p3)(- (cadr p3) (* n fl))) p4 2 300);标注边到分割线的距离
								 (text   (strcat c1ad0 "/1") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ (- L (* n fl)) 2) )) 150 1 1  "0");加编号1(断点)								 
										)
								(progn
                (MK-line1 (LIST (LIST (car p2) (-(cadr p2) (- (* n fl) 10))) (list(car p3)(- (cadr p3) (- (* n fl) 10)))));绘制分割线非手工下料
								(text  (strcat c1ad0 "/1") (LIST (+ (car p2) (/ c1ad2 2)) (- (cadr p2) (- (* n fl) (/ (- fl 10) 2)))) 300 1 1 "0")
								(dim (list(car p3)(- (cadr p3) (* (1- n) fl))) (list (car p3)(- (cadr p3) (+ (* (1- n) fl) (- fl 10)))) 2 300)
								(setq p5 (list (- (car p4) c1ad6) (+ (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ h3 2))));获取开口定位第一点
								(MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口
								(dim p5  (list (- (car p5) c1ad3 2) (cadr p5))  1 50)(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸
								(dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 1 50);标注马口到边的距离	
								(line1  (list (car p3) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 2) (line1 (list(car p2) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 1);绘制打标点							
							(if (or (= c1ad9 0) (= c1ad11 0))
									   (progn (line1 (list (car p3) (- (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 2);绘制打标点1	
											      (line1 (list (car p3) (+ (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 2);绘制打标点2
											       (line1 (list (car p2) (- (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 1);绘制打标点3
											      (line1 (list (car p2) (+ (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 1))	;绘制打标点4										  																			 
								     (progn (line1 (list (car p3) (- (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 2);绘制打标点1	
									          (line1 (list (car p3) (+ (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ L 8))) 2);绘制打标点2	
									     ))									
								(dim    (list (car p3) (-(cadr p2) (- (* n fl) 10))) p4 2 300);标注边到分割线的距离
							  (text   (strcat c1ad0 "/2") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ (- L (* n fl) 10) 2) )) 150 1 1  "0");加编号2
								)))		
            ;间隔分段线																
								(progn
	               (if (> (- L1 fl) (+ h3 100));条件L减去板宽大于弧长+100(100是给弧长预留的直缝焊接边),代表还可以进行一次手工下料									 
								 (progn	
		             (MK-line1 (LIST (LIST (car p2)(- (cadr p2) (* n fl))) (list(car p3)(- (cadr p3) (* n fl)))))	 
							   (text  "手工下料" (LIST (+ (car p2) (/ c1ad2 2)) (- (cadr p2) (- (* n fl) (/ fl 2)))) 300 7 1 "0")	 
							   (dim (list(car p3)(- (cadr p3) (* (1- n) fl))) (list(car p3)(- (cadr p3) (* n fl))) 2 300)
		             ;上面三行复制的重复代码,继续一次手工下料,下面开始开口							 
								 (setq p5 (list (- (car p4) c1ad6) (+ (cadr p4) (/ (- L (* n fl)) 2) (/ h3 2))));获取开口定位第一点
								 (MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口
								 (dim p5  (list (- (car p5) c1ad3 2) (cadr p5))  1 50)(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸
								 (dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (+ (cadr p4) (/ (- L (* n fl)) 2))) 1 50);标注马口到边的距离
								 (line1  (list (car p3) (+ (cadr p4) (/ (- L (* n fl)) 2) )) 2) (line1 (list(car p2) (+ (cadr p1) (/ (- L (* n fl)) 2) )) 1);绘制打标点								 
									 									 									 
								 (dim    (list(car p3)(- (cadr p3) (* n fl))) p4 2 300);标注边到分割线的距离
								 (text   (strcat c1ad0 "/1") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ (- L (* n fl)) 2) )) 150 1 1  "0");加编号1
								 )
								(progn
                (MK-line1 (LIST (LIST (car p2) (-(cadr p2) (- (* n fl) 10))) (list(car p3)(- (cadr p3) (- (* n fl) 10)))))
								(text  (strcat c1ad0 "/1") (LIST (+ (car p2) (/ c1ad2 2)) (- (cadr p2) (- (* n fl) (/ (- fl 10) 2)))) 300 1 1 "0")
								(dim (list(car p3)(- (cadr p3) (* (1- n) fl))) (list (car p3)(- (cadr p3) (+ (* (1- n) fl) (- fl 10)))) 2 300)
								(setq p5 (list (- (car p4) c1ad6) (+ (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2)) (/ h3 2))));获取开口定位第一点
								(MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口
								(dim p5  (list (- (car p5) c1ad3 2) (cadr p5))  1 50)(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸
								(dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 1 50);标注马口到边的距离	
								(line1  (list (car p3) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 2) (line1 (list(car p2) (- (cadr p3) (* (- n 1) fl) (/ (- fl 10) 2))) 1);绘制打标点																
	               (dim    (list (car p3) (-(cadr p2) (- (* n fl) 10))) p4 2 300);标注边到分割线的距离
							  (text   (strcat c1ad0 "/2") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ (- L (* n fl) 10) 2) )) 150 1 1  "0");加编号2
								)							 
								 )	))						
														 	 
								  )
								   )))			
			        (setq n(1+ n)
				           s1(1- s1)
				           L1(- L1 fl))		   
		                           )
			   (if (or (< C1aD2 fl) (< L fl)) ;设置假设条件,当管件高度小于分料板宽时
				 (progn
					(setq p5 (list (- (car p4) c1ad6) (+ (cadr p4) (/ L 2) (/ h3 2))));获取开口定位第一点,开在圆管中心处
					(MK-line (list p5 (list (- (car p5) c1ad3 2) (cadr p5)) (list (- (car p5) c1ad3 2) (- (cadr p5) h3)) (list (car p5) (- (cadr p5) h3)) ));绘制开口 
					(dim p5  (list (- (car p5) c1ad3 2) (cadr p5))  1 50)(dim (list (- (car p5) c1ad3 2) (cadr p5)) (list (-(car p5) c1ad3 2) (- (cadr p5) h3))2 -50);标注开口尺寸 
					(dim (list (car p5) (- (cadr p5) (/ h3 2))) (list (car p4) (+ (cadr p4) (/ L 2) (/ h3 2))) 1 50);标注马口到边的距离	 
					(line1  (list (car p3)  (+ (cadr p4) (/ L 2))  ) 2) (line1 (list(car p2) (+ (cadr p4) (/ L 2))) 1);绘制打标点 
					(text   (strcat c1ad0 "/1") (list (+ (car p1) (/ c1ad2 2)) (+ (cadr p4) (/ L 2))) 200 1 1  "0");加编号2
				 ))		
				;主管绘制完毕,下面开始绘制马口
				
	 (setq p6 (list (- (car p4) 200) (- (cadr p4) 1000));马口插入第一点
         p7	(list (car p6) (+ (cadr p6) c1ad5));马口高度
		     p8 (list (car p6) (+ (cadr p7) r));马口弧边辅助中心点
		     p9 (list (+ (car p6) (/ c1ad4 2)) (+ (cadr p7) h2));马口宽弧终点
		     p10(list (+ (car p9) c1ad3) (cadr p9));马口长绘制
         P11(list (+ (car p10) (/ c1ad4 2)) (cadr p7));马口弧边第二点
				 p12(list (car p11) (cadr p8));马口弧边辅助中心点2
				 p13(list (car p11) (cadr p6));马口高度2
		     p14(list (car p10) (cadr p6));马口长绘制2
				 p15(list (car p9) (cadr p6)));马口长绘制2第二边
		(MK-line1 (list p6 p7));绘制第一个马口高度斜边
    (mk-arc p8 p7 p9)	 
		(MK-line1 (list p9 p10));绘制第一个马口长
	  (mk-arc p12 p10 p11) 
		(MK-line1 (list p11 p13 p14 p15 p6));绘制剩余直段
		(line1  p14 3) (line1  p15 3);绘制打标点
		(text "2" (list(+ (car p6) (/ c1ad4 4)) (- (cadr p7) (/ c1ad5 2))) 50 4 1 "0");标注数量
		
		(text (strcat c1ad0 "/3")  (list(+ (car p9) (/ c1ad3 2)) (- (cadr p7) (/ c1ad5 2))) 150 1 1 "0");标注数量		
				
				
		(dim p6 p7 2 -30) (dim p9 p10 1 30) (dim p10 p11 1 30);标注马口
		(text (strcat "圆管的外径 " (rtos c1ad1))  (list (car p1) (- (cadr p1) 300)) 150 7 0 "序号图层")
    (text (strcat "圆管的长度 " (rtos c1ad2))  (list (car p1) (- (cadr p1) 550)) 150 7 0 "序号图层")
    (text (strcat "支管的长度 " (rtos c1ad3))  (list (car p1) (- (cadr p1) 800)) 150 7 0 "序号图层")	
	  (text (strcat "支管的宽度 " (rtos c1ad4))  (list (car p1) (- (cadr p1) 1050)) 150 7 0 "序号图层")
	  (text (strcat "支管的高度 " (rtos c1ad5))  (list (car p1) (- (cadr p1) 1300)) 150 7 0 "序号图层")
	  (text (strcat "支管嵌入量 " (rtos c1ad6))  (list (car p1) (- (cadr p1) 1550)) 150 7 0 "序号图层")
	 (if (/= c1ad11 0)
    (text (strcat "圆台大口直径 " (rtos c1ad11))  (list (car p1) (- (cadr p1) 1800)) 150 7 0 "序号图层"))
			)
	
(defun y2(pt0 / d1 d2 d3 d4 d5 d6 d7 d8 d8a p1 p2 p3 p4 pt1 s1 s2 s3 s4 s5) ;引用函数，
  (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
;下面为获取基础数据参数  
	(cond ((= c1ad10 0) ;C1ad10为变径工艺,当为0时,代表变径大口焊接
				(progn(setq d1 (- c1ad11 c1ad7);d1为大口直径
								    d2 (- c1ad1 c1ad7 -1);d2为小口直径
								    d3 1095) ));D3为圆台高度
				((= c1ad10 1) ;C1ad10为变径工艺,当为1时,代表变径大口翻遍12
				(progn(setq d1 (- c1ad11 c1ad7 -1);d1为大口直径
								    d2 (- c1ad1 c1ad7 -1);d2为小口直径
								    d3 (+ 1100 (- 12 c1ad7)))));D3为圆台高度				     
				((= c1ad10 2) ;C1ad10为变径工艺,当为2时,代表变径大口翻遍15
				(progn(setq d1 (- c1ad11 c1ad7 -1);d1为大口直径
								    d2 (- c1ad1 c1ad7 -1);d2为小口直径
								    d3 (+ 1100 (- 15 c1ad7))))))					   
					
	    (setq d4(/ (* d1 d3) (- d1 d2));H整体圆锥体高；h=dh/D-d
            d5(sqrt(+ (* d4 d4) (/ (* d1 d1) 4)));R整体圆锥展开半径： R=SQRT (H2+D2/4)
				    d6(- d4 d3);h1 圆锥上半部分长度
				    d7(/ (* d6 d5) d4);r 圆锥上半部展开半径
            d8(/ (* pi d1) d5 2);a 展开料夹角弧度a=pi*d1/R1;这里直接将角度转成弧度系数了，角度=弧度/180/pi
				    d8a(* d8 -1))
;下面为开始绘制圆台数据
	   (setq  pt1(polar pt0 pi (- d7 (/ c1ad2 2) 1000))
	          p1(polar pt1 d8a d7)
	          p2(polar pt1 d8 d7)
	          p3(polar pt1 d8a d5)
	          p4(polar pt1 d8 d5))4
	(setq s1 (mk-arc pt1 p1 p2)
        s2 (mk-arc pt1 p3 p4))
	(dar p1 p2 pt1 50)(dar p3 p4  pt1 100) 
	(mk-line1 (list p1 p3))(mk-line1 (list p2 p4))
  (dal p2 p4 (list (car p2) (+ (cadr p4) 50))	)

(if (= c1ad12 0)	;当变径对齐方式为四等分的时候
(progn
(setq s3 (XLRX-Curve-getUniformPoints s1 4))
(setq s4 (XLRX-Curve-getUniformPoints s2 4))
(setq s5 (cadr s3))
(text (strcat c1ad0 "/4")  (list (+ (car s5) 600) (cadr s5)) 150 1 1 "0")	
(mapcar (function (lambda (p1 p2)
	(entmakex (list '(0 . "line") (cons 10 p1) (cons 62 2) (cons 11 (polar p1 (angle p1 p2)1))))
	(entmakex (list '(0 . "line") (cons 10 p2) (cons 62 2) (cons 11 (polar p2 (angle p1 p2) -1))))	
  (entmakex (list '(0 . "line") (cons 10 p1) (cons 62 1) (cons 8 "3中心线层")(cons 11 p2)))										
	))   s3 s4))	
(progn
(setq s3 (XLRX-Curve-getUniformPoints s1 8))
(setq s4 (XLRX-Curve-getUniformPoints s2 8))	
(setq s3 (cdrnth 1 s3))(setq s3 (carnth 3 s3))	
(setq s4 (cdrnth 1 s4))(setq s4 (carnth 3 s4))		
(setq s5 (cadr s3))
(text (strcat c1ad0 "/4")  (list (+ (car s5) 600) (cadr s5)) 150 1 1 "0")
(mapcar (function (lambda (p1 p2)
	;(entmakex (list '(0 . "line") (cons 10 p1) (cons 62 2) (cons 11 (polar p1 (angle p1 p2)1))))
	(entmakex (list '(0 . "line") (cons 10 p2) (cons 62 2) (cons 11 (polar p2 (angle p1 p2) -1))))	
  (entmakex (list '(0 . "line") (cons 10 p1) (cons 62 1) (cons 8 "3中心线层")(cons 11 p2)))										
	))   s3 s4)
(setq s3 (cadr s3)  s4 (cadr s4))
(entmake (list '(0 . "line") (cons 10 s3) (cons 62 2) (cons 11 (polar s3 (angle s3 s4)1))))

))	
	
	
	

   (command "._undo" "_end")
(setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ))	
	
	
	
	
	
	
(defun test1 (/ *excel* *sheet* *xlapp*  exname pcs pcs1 pt0)
  (vl-load-com)
  ;(setq exname "C:\\Users\\Administrator\\Desktop\\自动生成参数1.xlsx")
	(setq exname "D:\\小辉插件\\标准模板\\自动化生成数据表.xls")
  (setq *excel* (vlax-create-object "excel.application"))
  (setq *xlapp* (vlax-invoke-method (vlax-get-property *excel* 'Workbooks) 'Open exname))
  (vla-put-visible *excel* 0)  ;;显示工作表
  (setq *sheet* (vlax-get-property (vlax-get-property *xlapp* 'Worksheets) 'item "圆管开方口"))
	(setq pcs (atof(Ljx-read-excel-text1 "J" 2 *sheet*)))
	(setq pt0(getpoint "请输入插入的位置："))
	(SETQ pcs1 1)
	    (while	
			
				(> pcs 0)
				(progn
				(setq pcs(- pcs 1))
				(SETQ pcs1(+ pcs1 1))
				(setq pt0 (list (+ (car pt0) 8000) (cadr pt0)))
			(setq	c1ad0 (itoa(atoi(Ljx-read-excel-text1  "B" PCS1 *sheet*)))
				    c1ad1 (atof(Ljx-read-excel-text1  "C" PCS1 *sheet*))
				    c1ad2 (atof(Ljx-read-excel-text1  "D" PCS1 *sheet*))
				    c1ad3 (atof(Ljx-read-excel-text1  "E" PCS1 *sheet*))
			    	c1ad4 (atof(Ljx-read-excel-text1  "F" PCS1 *sheet*))
				    c1ad5 (atof(Ljx-read-excel-text1  "G" PCS1 *sheet*))
			      c1ad6 (atof(Ljx-read-excel-text1  "H" PCS1 *sheet*))
				    c1ad11 (atof(Ljx-read-excel-text1  "I" PCS1 *sheet*))
				)
				(c1a pt0)	
				(if (/= c1ad11 0) (y2 pt0))	
					
			))   
  (vlax-invoke-method (vlax-get-property *excel* "ActiveWorkbook") 'Close 0)
  (vlax-invoke-method *excel* 'QUIT)
  (vlax-release-object *sheet*) 
  (vlax-release-object *xlapp*)
)	
(defun Ljx-read-excel-data1 (vv hor sh) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2))
)	
;;;;;读取数excel数据函数输出text格式
(defun Ljx-read-excel-text1 (vv hor sh /  ru) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vl-princ-to-string (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2)))
)
(defun ljx-vlxls-get-range-value1 ( sheet rangeid / range value valuelist )
  (setq range (vlax-get-property sheet 'Range rangeid))
  (setq value (vlax-get-property range 'Value2))
  (cond
    ((= (vlax-variant-type value)  8204);;;为数组时，即为区域;
        (progn
          (setq value (vlax-safearray->list(vlax-variant-value value)))
          (setq valuelist (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) value))
        )
    )
    ( T;;;;为单个单元格;
      (setq valuelist (vlax-variant-value value))
    )
  );;;;cond
  valuelist
)	
	
	
	
	
	
	
	
	(if (/= 'str (type c1ad0))
		(progn (setq c1ad0 "1")
			
      (setq c1ad1 1200)(setq c1ad2 3895)(setq c1ad3 597)(setq c1ad4 297)
			(setq c1ad5 148.5)(setq c1ad6 95)
			(setq c1ad7 1.5)(setq c1ad8 0) (setq c1ad9 0)(setq c1ad10 0)(setq c1ad11 1300)(setq c1ad12 0)	
		))
	(h-read1  "c1a")
  (defun getdata1()
		(setq 
			c1ad0 (get_tile "d0")
			c1ad1 (atof (get_tile "d1"))
			c1ad2 (atof (get_tile "d2"))
			c1ad3 (atof (get_tile "d3"))
			c1ad4 (atof (get_tile "d4"))
			c1ad5 (atof (get_tile "d5"));分料数据
			c1ad6 (atof (get_tile "d6"))
			c1ad7 (atof (get_tile "d7"))
			c1ad8 (atoi (get_tile "d8"))
			c1ad9 (atoi (get_tile "d9"))
			c1ad10 (atoi (get_tile "d10"))
			c1ad11 (atof (get_tile "d11"))
			c1ad12 (atoi (get_tile "d12"))
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "圆管开方口展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
  (set_tile "d0" c1ad0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos c1ad1 2 2));
  (set_tile "d2" (rtos c1ad2 2 2))
  (set_tile "d3" (rtos c1ad3 2 2));
	(set_tile "d4" (rtos c1ad4 2 2 ))
	(set_tile "d5" (rtos c1ad5 2 2 ))
	(set_tile "d6" (rtos c1ad6 2 2 ))
	(set_tile "d7" (rtos c1ad7 2 2 ))
	(if (/= c1ad8 nil)(set_tile "d8" (rtos c1ad8 2)))
	(if (/= c1ad9 nil)(set_tile "d9" (rtos c1ad9 2)))
	(MODE_TILE "d10"  (if (= c1ad9  0)  1 0))
	(MODE_TILE "d11"  (if (= c1ad9  0)  1 0))
	(MODE_TILE "d12"  (if (= c1ad9  0)  1 0))
	(if (/= c1ad10 nil)(set_tile "d10" (rtos c1ad10 2)))
	(set_tile "d11" (rtos c1ad11 2 2 ))
	(if (/= c1ad12 nil)(set_tile "d12" (rtos c1ad12 2)))
  (mode_tile "d0" 2);设置d0为焦
	
	
	
	
	(action_tile "d9" 
	
    "(MODE_TILE \"d10\"  (if (= $value \"1\")  0 1))
		 (MODE_TILE \"d11\"  (if (= $value \"1\")  0 1))
     (MODE_TILE \"d12\"  (if (= $value \"1\")  0 1))"
    )
	
	
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;当按下确认按钮的时候保存控件值，然后退出界面,并执行对于功能函数
  (action_tile "cancel" "(getdata1)(done_dialog 0)") ;当按下取消按钮的时候保存控件值，然后退出界面
	(action_tile "help" "(getdata1)(done_dialog 2)") ;当按下取消按钮的时候保存控件值，然后退出界面
	(action_tile "EL1" "(getdata1)(done_dialog 3)");当按下批量读取EXCEL数据时,保存控件值,然后退出界面
	
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;鼠标按下确认后，开始执行这里的操作
					(progn
						(prompt"\n 用户取消绘制图纸！")));鼠标按下确认后，将各个控件的值汇总到这里，传递给功能函数，执行功能操作		
		((= re 2)
			(progn
				(alert "这里填充说明")	
			))
	  ((= re 3)
				(test1);批量读取CAD数据	
			)	
		
		((= re 1)
			(progn
				(setq pt0(getpoint "请输入插入的位置："))
				(c1a pt0)
				(if (and (= c1ad9 1) (/= c1ad11 0)) (y2 pt0))
				
			)
			
		)
	
	)
	
	(h-save1  '(c1ad0 c1ad1 c1ad2 c1ad3 c1ad4 c1ad5 c1ad6 c1ad7 c1ad8 c1ad9 c1ad10 c1ad11 c1ad12) "c1a")
	 (setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")	
	(princ)
)

;方直管展开 C3
(defun c:c3(/ c3 c3a c3b c3c c3d1 c3d2 c3d3 c3d4 c3d5 dcl_file dcl_id getdata1 getdata2 make-dclcs pt0 re)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "矩形直管口字型展开程序:dialog"
				 "{ // start dcl"
				 "label = \"矩形直管口字型展开程序\";"
				 ":row{"
				 ":boxed_column{"
				 ":edit_box{label=\"直管序号为(个)：\";key=\"d1\"; edit_width=6;}"
				 ":edit_box{label=\"直管长度为(mm)：\";key=\"d2\"; edit_width=6;}"
				 ":edit_box{label=\"直管宽度为(mm)：\";key=\"d3\"; edit_width=6;}"
			   ":edit_box{label=\"直管高度为(mm)：\";key=\"d4\"; edit_width=6;}"			        			         
				 "} "			 				
				 ":boxed_column{"
				 ":edit_box  {label=\"板材厚度为(mm)：\";key=\"d5\"; edit_width=8;is_tab_stop=false;}"
				 ":popup_list{label=\"分料尺寸：\";key=\"d7\";list=\"1219\\n1250\\n1500\\n不分料\"; edit_width=8;is_tab_stop=false;}"
				 ":popup_list{label=\"直管样式：\";key=\"d8\";list=\"口字形\\nU型\\nL型\\n四片料\"; edit_width=8;is_tab_stop=false;}"
				 ":edit_box  {label=\"起步长度为(mm)：\";key=\"d9\"; edit_width=8;is_tab_stop=false;}"
				 ":edit_box  {label=\"刻线长度为(mm)：\";key=\"d10\"; edit_width=8;is_tab_stop=false;}"
				 "}}"
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\";
is_default=true;height=1;} "	":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;height=2;}"":button{label=\"帮助(&H)\";key=\"help\";is_cancel=true;is_tab_stop=false;height=2;}""}"
				 
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 )		      
		)
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c3 (pt0 / d2 d3  fl i1 i10 i11 i2 i3 i4 i5 i6 i7 i8 i9 l l1 n qd x)
		;板材筛选条件	 
		(cond ((= c3d7 0)(setq fl 1219))
      ((= c3d7 1) (setq fl 1250))
      ((= c3d7 2) (setq fl 1500))
    	((= c3d7 3) (setq fl 0)))
	    (setq qd c3d9) 
		  (setq kx c3d10)
		(if ( > c3d2 1000)
			(progn
				(setq d3 c3d2
					d2 c3d3))
			(progn
				(setq d2 c3d2
					d3 c3d3)))  
		(setq i1 (AA pt0 0 qd)	
			i2 (AA i1  0 (- d2 (* c3d5 2)))	
			i3 (AA i2  0 (- d3 (* c3d5 2)))
			i4 (AA i3  0 (- d2 (* c3d5 2)))	
			i5 (AA i4  0 (- d3 (* c3d5 2) qd))
			i6 (AA i5  C3d4 0)
			i7 (AB i6 I4  0 0)
			i8 (AB i7 I3  0 0)
			I9 (AB i8 I2  0 0)
			I10(AB i9 I1  0 0)
			I11(AB i10 PT0  0 0))
		(MK-line (list pt0 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 ))
				(MK-line3 (list i1 i10) 1 "3中心线层") (MK-line3 (list i2 i9) 1 "3中心线层");绘制虚线
		(MK-line3 (list i3 i8) 1 "3中心线层") (MK-line3 (list i4 i7) 1 "3中心线层");绘制虚线
		(line2 i1 1 kx)(line2 i2 1 kx)(line2 i3 1 kx)(line2 i4 1 kx)(line2 i7 2 kx)(line2 i8 2 kx)(line2 i9 2 kx)(line2 i10 2 kx);打标点

    (command "-DIMSTYLE" "R" "m-10")
    (setvar "dimtix" 1)
    (command "dimlinear" pt0 i1 "@-50,50")(command "dimlinear" i4 i5 "@-50,50")
		(dim1 i1 i2 2 -50 "m-15") (dim1 i2 i3 2 -50 "m-15")
		(dim1 i3 i4 2  -50 "m-15")(dim1 pt0 i5 2 -450 "m-15")(dim1 i5 i6 1 50 "m-15")
		
		;下面开始分料
		(if (/= FL  0);当需要分料的情况时S
			(progn
				(setq L (* (+ (- d2 (* c3d5 2)) (- d3 (* c3d5 2))) 2));计算直管展开的长度
				(setq X(fix(/ L  FL)));用总长/板宽得到的整数判断是否需要分料
				(setq n 1
					L1 L);L1为分料后所剩余的直段
				
				(while (and (> X 0) (> C3D4 FL))
					(if (and (= x 1) (< (- L1 fl) 120));120为预留的最小直缝焊长度。
						(progn 
							(MK-line1 (LIST (LIST (car pt0) (+ (cadr pt0) (- L 120))) (list(car i11)(+ (cadr i11) (- L 120)))))
							(text (strcat"z" (rtos C3D1) "/2") (LIST (+ (car pt0) (/ C3D4 2)) (+ (cadr pt0) (- (* n (- L1 120)) (/ (- L1 120) 2)))) 300 1 1 "0")
							(dim (list(car i11)(+ (cadr i11) (* (1- n) fl))) (list(car i11)(+ (cadr i11) (- L 120))) 2 350)
							(dim1  (list(car i11)(+ (cadr i11) (- L 120))) i6 2 350 "m-15")	
						)
						(progn
							(MK-line1 (LIST (LIST (car pt0)(+ (cadr pt0) (* n fl))) (list(car i11)(+ (cadr i11) (* n fl)))))
							(text  "手工下料" (LIST (+ (car pt0) (/ C3D4 2)) (+ (cadr pt0) (- (* n fl) (/ fl 2)))) 330 7 1 "0")
							(dim (list(car i11)(+ (cadr i11) (* (1- n) fl))) (list(car i11)(+ (cadr i11) (* n fl))) 2 350)
							(if (= x 1) (dim1 (list(car i11)(+ (cadr i11) (* n fl))) i6 2 350 "m-15")) 				  
						)							
					)
					(setq n (1+ n)
						x(1- x)
						L1(- L1 fl))	
				)
				(text  (strcat "z"(rtos C3D1) "/1") (list(+ (car pt0) (/ C3D4 2)) (- (cadr i6) (/ (- (cadr i6) (+ (cadr i11) (* (1- n) fl))) 2))) 300 1 1 "0")		
			)
			(text (strcat "z" (rtos C3D1) "/1") (list(+ (car pt0) (/ C3D4 2)) (+ (cadr pt0) (/ L 2))) 300 1 1 "0")
		)
		
	  ;标注尺寸	
		(text (strcat "直管的尺寸为      "(rtos d2 2 2) "*" (rtos d3 2 2) "*" (rtos c3d4 2 2)) (list  (car pt0) (- (cadr pt0) 800)) 150 7 0 "序号图层" )	
		(text (strcat "展开后的尺寸为     " (rtos (- (* (+ d2 d3) 2) (* c3d5 8)) 2 2) "*" (rtos c3d5 2 2) "t" ) (list  (car pt0)  (- (cadr pt0) 1050)) 150 7 0 "序号图层" )
		(text         "直管制作形式为 口型"  (list  (car pt0)  (- (cadr pt0) 1300)) 150 7 0 "序号图层" )	
		(if (> c3d4 4000) (text "注意：直管长度超过4m,无折弯机可折弯！"  (list  (car pt0)  (- (cadr pt0) 1550)) 150 2 0 "序号图层" ))
	)
	(defun c3a (pt0 / p1 p2 p3 p4 p5 p6 p7 pt1 qd)
		
		(setq qd c3d9);当宽度小于300，默认预留直缝焊接距离108.5，否则148.5起步	
		(setq kx c3d10)
		(setq p1(list (car pt0) (+ (cadr pt0) qd)))
    (setq p2(list (car pt0) (+ (cadr p1) (- c3d2 (* c3d5 2)))))
    (setq p3(list (car pt0) (+ (cadr p2) (- c3d3 (* c3d5 2) qd))))
    (setq p4(list (+ (car pt0) c3d4) (cadr p3)))
    (setq p5(list (car p4) (cadr p2)))
    (setq p6(list (car p4) (cadr p1)))
    (setq p7(list (car p4) (cadr pt0)))
		(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7))
		(text  (strcat "z" (rtos C3D1) "/2") (list(+ (car pt0) (/ C3D4 2)) (+ (cadr p1) (/ (- c3d2 (* c3d5 2))2) )) 300 1 1 "0")
		(MK-line3 (list p1 p6) 1 "3中心线层")(MK-line3 (list p2 p5) 1 "3中心线层")
		(line2 p1 1 kx) (line2 p2 1 kx)(line2 p5 2 kx) (line2 p6 2 kx)
		(command "-DIMSTYLE" "R" "m-8")
		(setvar "dimtix" 1)
		(command "dimlinear" pt0 p1 "@-50,50")
		(command "dimlinear" p2 p3 "@-50,50")
		(dim1 p1 p2 2 -50"m-8")
		(dim1 pt0 p3 2 -180"m-10") (dim1 p3 p4 1 50"m-10")
    (setq pt1(list (car pt0) (+ (cadr p3) 400)))
		(setq p1(list (car pt1) (+ (cadr pt1) qd)))
    (setq p2(list (car pt1) (+ (cadr p1) (- c3d2 (* c3d5 2)))))
    (setq p3(list (car pt1) (+ (cadr p2) (- c3d3 (* c3d5 2) qd))))
    (setq p4(list (+ (car pt1) c3d4) (cadr p3)))
    (setq p5(list (car p4) (cadr p2)))
    (setq p6(list (car p4) (cadr p1)))
    (setq p7(list (car p4) (cadr pt1)))
		(MK-line (list pt1 p1 p2 p3 p4 p5 p6 p7))
		(text  (strcat "z" (rtos C3D1) "/1") (list(+ (car pt1) (/ C3D4 2)) (+ (cadr p1) (/ (- c3d2 (* c3d5 2))2) )) 300 1 1 "0")
		(MK-line3 (list p1 p6) 1 "3中心线层")(MK-line3 (list p2 p5) 1 "3中心线层")
		(line2 p1 1 kx) (line2 p2 1 kx)(line2 p5 2 kx) (line2 p6 2 kx)
		(command "-DIMSTYLE" "R" "m-8")
		(setvar "dimtix" 1)
		(command "dimlinear" pt1 p1 "@-50,50")
		(command "dimlinear" p2 p3 "@-50,50")
    (dim1 p1 p2 2 -50"m-8") 
		(dim1 pt1 p3 2 -180"m-10") (dim1 p3 p4 1 50"m-10")
		
		(text (strcat "直管的尺寸为   "(rtos c3d2 2 2) "*" (rtos c3d3 2 2) "*" (rtos c3d4 2 2)) (list  (car pt0) (- (cadr pt0) 800)) 150 7 0 "序号图层" )	
		(text (strcat "展开的尺寸为   " (rtos (- (* (+ c3d2 c3d3) 2) (* c3d5 8)) 2 2) "*" (rtos c3d5 2 2) "t" ) (list  (car pt0)  (- (cadr pt0) 1050)) 150 7 0 "序号图层" )	
		(text         "直管制作形式为 U型"  (list  (car pt0)  (- (cadr pt0) 1300)) 150 7 0 "序号图层" )
		(if (> c3d4 4000) (text "注意：直管长度超过4m,无折弯机可折弯！"  (list  (car pt0)  (- (cadr pt0) 1550)) 150 2 0 "序号图层" ))
	)
	(defun c3b (pt0 /  p1 p2 p3 p4 p5 pt1)
		(setq kx c3d10)
		(setq p1 (AA PT0 0 (- C3D2 (* c3d5 2)))
			P2 (AA P1  0 (- C3D3 (* c3d5 2)))
			P3 (AA P2  C3D4 0)
			P4 (AB P3 P1  0  0)
			P5 (AB P4 PT0  0  0))
		(MK-line (list pt0 p1 p2 p3 p4 p5))
		(line2 p1 1 kx) (line2 p4 2 kx)
		(MK-line3 (list p1 p4) 1 "3中心线层")
		(dim1 pt0 p1 2 -50"m-10")(dim1 p1 p2 2 -50"m-10")(dim1 pt0 p2 2 -230 "m-15")(dim1 p2 p3 1 50 "m-15")
		(text  (strcat "z" (rtos C3D1) "/2") (list(+ (car pt0) (/ C3D4 2)) (CADR P1)) 300 1 1 "0")
		(setq   pt1(AA P2 0 600)
			p1 (AA PT1 0 (- C3D2 (* c3d5 2)))
			P2 (AA P1  0 (- C3D3 (* c3d5 2)))
			P3 (AA P2  C3D4 0)
			P4 (AB P3 P1  0  0)
			P5 (AB P4 PT1  0  0))
		(MK-line (list pt1 p1 p2 p3 p4 p5))
		(line2 p1 1 kx) (line2 p4 2 kx)
		(MK-line3 (list p1 p4) 1 "3中心线层")
		(dim1 pt1 p1 2 -50"m-10")(dim1 p1 p2 2 -50"m-10")(dim1 pt1 p2 2 -230 "m-15")(dim1 p2 p3 1 50 "m-15")
		(text  (strcat "z" (rtos C3D1) "/1") (list(+ (car pt1) (/ C3D4 2)) (CADR P1)) 300 1 1 "0")
		(text (strcat "直管的尺寸为   "(rtos c3d2 2 2) "*" (rtos c3d3 2 2) "*" (rtos c3d4 2 2)) (list  (car pt0) (- (cadr pt0) 800)) 150 7 0 "序号图层" )	
		(text (strcat "展开的尺寸为   " (rtos (- (* (+ c3d2 c3d3) 2) (* c3d5 8)) 2 2) "*" (rtos c3d5 2 2) "t" ) (list  (car pt0)  (- (cadr pt0) 1050)) 150 7 0 "序号图层" )	
		(text         "直管制作形式为 L型"  (list  (car pt0)  (- (cadr pt0) 1300)) 150 7 0 "序号图层" )	
		(if (> c3d4 4000) (text "注意：直管长度超过4m,无折弯机可折弯！"  (list  (car pt0)  (- (cadr pt0) 1550)) 150 2 0 "序号图层" ))
	)	
	
	(defun c3c (pt0 /  p1 p2 p3 p4 p5 p6 p7)
		
		(setq p1(AA PT0 0 (- C3D2 (* c3d5 2)))
			P2 (AA p1  C3D4 0)
			P3 (AB P2 Pt0  0  0)
			p4 (AA p1  0 600)
			p5 (AA p4  0 (- C3D3 (* c3d5 2)))
			p6 (AA p5  C3D4 0)
			p7 (AB P6 P4  0  0))
		(MK-line (list pt0 p1 p2 p3 )) (MK-line (list p4 p5 p6 p7))
		(dim1 pt0 p1 2 -50 "m-10")(dim1 p1 p2 1 50 "m-10")(dim1 p4 p5 2 -50 "m-10")(dim1 p5 p6 1 50 "m-10")
		(text  (strcat "z" (rtos C3D1) "/1") (list(+ (car pt0) (/ C3D4 2)) (+ (CADR Pt0) (/ (- C3D2 (* c3d5 2)) 2))) 300 1 1 "0")
		(text  "2" (list(+ (car pt0) (/ C3D4 2) 400) (+ (CADR Pt0) (/ (- C3D2 (* c3d5 2)) 2))) 100 4 1 "0")
		(text  (strcat "z" (rtos C3D1) "/2") (list(+ (car p4) (/ C3D4 2)) (+ (CADR P4) (/ (- C3D3 (* c3d5 2)) 2))) 300 1 1 "0")
		(text  "2" (list(+ (car p4) (/ C3D4 2) 400) (+ (CADR P4) (/ (- C3D3 (* c3d5 2)) 2))) 100 4 1 "0")
		(text (strcat "直管的尺寸为   "(rtos c3d2 2 2) "*" (rtos c3d3 2 2) "*" (rtos c3d4 2 2)) (list  (car pt0) (- (cadr pt0) 800)) 150 7 0 "序号图层" )	
		(text (strcat "展开的尺寸为   " (rtos (- (* (+ c3d2 c3d3) 2) (* c3d5 8)) 2 2) "*" (rtos c3d5 2 2) "t" ) (list  (car pt0)  (- (cadr pt0) 1050)) 150 7 0 "序号图层" )	
		(text         "直管制作形式为四片料"  (list  (car pt0)  (- (cadr pt0) 1300)) 150 7 0 "序号图层" )	
	  (if (> c3d4 4000) (text "注意：直管长度超过4m,无折弯机可折弯！"  (list  (car pt0)  (- (cadr pt0) 1550)) 150 2 0 "序号图层" ))	
	)
	
	;;---------开始写面板调用函数
	(if (not c3d1)
		(progn (setq c3d1 1) ;判断变量是否存在并且为字符串，如果不是则进行初始化定义
			(setq c3d2 500);判断变量是否存在并且为字符串，如果不是则进行初始化定义
			(setq c3d3 500);判断变量是否存在并且为字符串，如果不是则进行初始化定义
			(setq c3d4 2697);判断变量是否存在并且为字符串，如果不是则进行初始化定义
			(setq c3d5 1.5)
			(setq c3d9 148.5)
			(setq c3d10 1)
		))
	
	(h-read1  "c3");读取注册表的数据
	(defun getdata1() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
    (setq c3d1  (atof(get_tile "d1")))
    (setq c3d2  (atof(get_tile "d2")))
    (setq c3d3  (atof(get_tile "d3")))
    (setq c3d4  (atof(get_tile "d4")))
    (setq c3d5  (atof(get_tile "d5")))
    (setq c3d7  (atoi(get_tile "d7")))
		(setq c3d8  (atoi(get_tile "d8")))
		(setq c3d9  (atof(get_tile "d9")))
		(setq c3d10  (atof(get_tile "d10")))
	)
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "矩形直管口字型展开程序" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	(set_tile "d1" (rtos c3d1 2 2)) ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d2" (rtos c3d2 2 2));将对应key的全局变量传递给控件
  (set_tile "d3" (rtos c3d3 2 2));将对应key的全局变量传递给控件
  (set_tile "d4" (rtos c3d4 2 2));将对应key的全局变量传递给控件
  (if (/= c3d5 nil)
		(set_tile "d5" (rtos c3d5 2 2)));将对应key的全局变量传递给控件
	(if (/= c3d7 nil)
		(set_tile "d7" (rtos c3d7 2 2)));将对应key的全局变量传递给控件
	(if (/= c3d8 nil)
		(set_tile "d8" (rtos c3d8 2 2)))
	(set_tile "d9" (rtos c3d9 2 2))
	(set_tile "d10" (rtos c3d10 2 2))
	
  (mode_tile "d1" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "1、4种展开汇总，统一命令为C3
2、重构代码，提升运行速度
3、口型自动分料优化，自动预留最小直缝焊距离120mm
4、U型直管当宽度小于300时，默认预留直缝焊距离108.5，大于则默认为148.5
5、直管展开长度总长超过4m会进行提示，折弯可能无法进行
 ")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint "请选择图形插入点"))
				(cond ((= c3d8 0)
								(c3 pt0))
					((= c3d8 1)
						(c3a pt0))
					((= c3d8 2)
						(c3B pt0))
					((= c3d8 3)
						(c3c pt0))
					
				)			
			))	
	)	
	
	(h-save1  '(c3d1 c3d2 c3d3 c3d4 c3d5  c3d7 c3d8 c3d9 c3d10) "c3");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;方变径展开 C4
(defun c:c4(/ c4 c4ad0 c4ad1 c4ad10 c4ad2 c4ad3 c4ad4 c4ad5 c4ad6 c4ad7 c4ad8 c4ad9 dcl_file dcl_id getdata1 ljx-read-excel-data1 ljx-read-excel-text1 ljx-vlxls-get-range-value1 make-dclcs pt0 re test1)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "矩形变径一键展开:dialog"
				 "{ // start dcl"
				 "label = \"矩形变径一键展开\";initial_focus=d0;"
          
			         ":row{"
				 ":column{label=\"数据\";"
				 ":edit_box{label=\"序号    (个)：\";key=\"d0\"; edit_width=7;}"
				 ":edit_box{label=\"入口宽  (mm)：\";key=\"d1\"; edit_width=7;}"
				 ":edit_box{label=\"入口深  (mm)：\";key=\"d2\"; edit_width=7;}"
			   ":edit_box{label=\"出口宽  (mm)：\";key=\"d3\"; edit_width=7;}"
			   ":edit_box{label=\"出口深  (mm)：\";key=\"d4\"; edit_width=7;}"
			   ":edit_box{label=\"宽偏移  (mm)：\";key=\"d5\"; edit_width=7;}"
			   ":edit_box{label=\"深偏移  (mm)：\";key=\"d6\"; edit_width=7;}"
				 ":edit_box{label=\"长度    (mm)：\";key=\"d7\"; edit_width=7;}"
				 ":edit_box{label=\"入口伸量(mm)：\";key=\"d8\"; edit_width=7;}"
				 ":edit_box{label=\"出口伸量(mm)：\";key=\"d9\"; edit_width=7;}}"
				 ":column{label=\"参数\";"
				 ":edit_box{label=\"风管厚度\";key=\"d10\"; edit_width=6;is_tab_stop=false;}"
				 ":popup_list{label=\"辅助视图\";key=\"d11\";list=\"无\\n俯视\\n仰视\"; edit_width=6;is_tab_stop=false;}"
				 ":edit_box{label=\"刻线长度(mm)：\";key=\"d12\"; edit_width=6;}"
			   ":button {label=\"读EXCEL数据\"; key = \"EL1\";is_tab_stop=false;} :spacer{height = 14;}}}"
				                             
                
				 
						 				
				 ":row{"":button{is_default= true;label=\"确定(&Q)\";key=\"accept\";
				 height=2;} "	":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;height=2;}" ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;height=2;}" "} "
			  
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 )		      
		)
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c4 (pt0 / d1 d10 d11 d12 d13 d1s d2 d2s d3 d3s d4 d4s d5s d6s d7s d8s d9s dx i1 i2 i3 i4 i5 i6 i7 o1 o2 o3 o4 o5 o6 o7 p1 p2 p3 p4 p5 p6 p7 pt1 pt2 pt3 u1 u10 u11 u12 u13 u14 u15 u2 u3 u4 u5 u6 u7 u8 u9 w1)
		(setq d1 (- c4ad1 (* 2 c4ad10));对宽度和深度再赋值
		      d2 (- c4ad2 (* 2 c4ad10))
		      d3 (- c4ad3 (* 2 c4ad10))			
		      d4 (- c4ad4 (* 2 c4ad10))
			    kx c4ad12
		)											
  (setq d10(sqrt(+ (* (abs (+ (- d4 d2) c4ad6)) (abs (+ (- d4 d2) c4ad6))) (* (- c4ad7 c4ad8 c4ad9) (- c4ad7 c4ad8 c4ad9))));前嵌板
        d11(sqrt(+ (* c4ad6 c4ad6) (* (- c4ad7 c4ad8 c4ad9) (- c4ad7 c4ad8 c4ad9))));后嵌板
        d12(sqrt(+ (* c4ad5 c4ad5) (* (- c4ad7 c4ad8 c4ad9) (- c4ad7 c4ad8 c4ad9))));左嵌板
        d13(sqrt(+ (* (abs (+ (- d3 d1) c4ad5)) (abs (+ (- d3 d1) c4ad5))) (* (- c4ad7 c4ad8 c4ad9) (- c4ad7 c4ad8 c4ad9)))));前嵌板
  
  
  ;下面为变径的前嵌板
   (setq p1(list (car pt0) (+ (cadr pt0) c4ad8)))
   (setq p2(list (- (car pt0) c4ad5) (+ (cadr p1) d10)))
   (setq p3(list (car p2) (+ (cadr p2) c4ad9)))
   (setq p4(list (- (car p3) d3) (cadr p3)))
   (setq p5(list (car p4) (cadr p2)))
   (setq p6(list (- (car p1) d1) (cadr p1)))
   (setq p7(list (car p6) (cadr pt0)))
  (setq w1(list (/ (+ (car pt0) (car p4)) 2) (/ (+ (cadr pt0) (cadr p4)) 2)))
	(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 ))
  (dim1 pt0 p1 2 -100 "m-8") (dim1 pt0 p3  2 100 "m-8") (dim1 p3 p4 1 50 "m-8")  
	(dim1 p7 pt0 1 -120 "m-8") (dim1 p4 p7 1 -200 "m-8") (dim1 p5 p4 2 50 "m-8");标注尺寸
		
	(line2 p1 2 kx) (line2 p2 2 kx) (line2 p5 1 kx) (line2 p6 1 kx)
  ;下面的为后嵌板
	(if (< c4ad5 0 )
	(setq pt1 (list  (+ (car pt0) 600 (* (abs c4ad5) 2))  (cadr pt0)))
	(setq pt1 (list (+ (car pt0) 600) (cadr pt0))))

  (setq  o1(list (car pt1) (+ (cadr pt1) c4ad8))
         o2(list (+ (car pt1) c4ad5) (+ (cadr o1) d11))
         o3(list (car o2) (+ (cadr o2) c4ad9))
         o4(list (+ (car o3) d3) (cadr o3))
         o5(list (car o4) (cadr o2))
         o6(list (+ (car o1) d1) (cadr o1))
         o7(list (car o6) (cadr pt1)))
	(MK-line (list pt1 o1 o2 o3 o4 o5 o6 o7 ))
  (dim1 o3 pt1 1 -100 "m-8") (dim1 o7 o4 2 100 "m-8")
 	(line2 o1 1 kx) (line2 o2 1 kx) (line2 o5 2 kx) (line2 o6 2 kx)
  ;下面的为左嵌板
  (setq pt2(list (car pt0) (+ (cadr p3) 600)))
   (setq i1(list (car pt2) (+ (cadr pt2) c4ad8)))
   (setq i2(list (- (car pt2) c4ad6) (+ (cadr i1) d12)))
   (setq i3(list (car i2) (+ (cadr i2) c4ad9)))
   (setq i4(list (- (car i3) d4) (cadr i3)))
   (setq i5(list (car i4) (cadr i2)))
   (setq i6(list (- (car i1) d2) (cadr i1)))
   (setq i7(list (car i6) (cadr pt2)))
	(MK-line (list pt2 i1 i2 i3 i4 i5 i6 i7 ))
	(dim1 i3 pt2 1 -350 "m-8") (dim1 i4 i3 1 50 "m-8") (dim1 i7 i4 2 -150 "m-8")(dim1 pt2 i7 1 -120 "m-8")
  (line2 i1 2 kx) (line2 i2 2 kx) (line2 i5 1 kx) (line2 i6 1 kx)
  ;下面的右嵌板
(if (< c4ad6 0 )
	(setq pt3(list (+ (car pt2) 600 (* (abs c4ad6) 2)) (cadr pt2)))
	(setq pt3(list (+ (car pt2) 600) (cadr pt2))))		
   (setq u1(list (car pt3) (+ (cadr pt3) c4ad8)))
   (setq u2(list (+ (car pt3) c4ad6) (+ (cadr u1) d13)))
   (setq u3(list (car u2) (+ (cadr u2) c4ad9)))
   (setq u4(list (+ (car u3) d4) (cadr u3)))
   (setq u5(list (car u4) (cadr u2)))
   (setq u6(list (+ (car u1) d2) (cadr u1)))
   (setq u7(list (car u6) (cadr pt3)))
	(MK-line (list pt3 u1 u2 u3 u4 u5 u6 u7 ))
	(dim1 pt3 u3 2 -100 "m-8") (dim1 u4 u3 1 50 "m-8")	(dim1 u4 u7 1 -200 "m-8") (dim1 pt3 u7 1 -120 "m-8")
	(line2 u1 1 kx)(line2 u2 1 kx)(line2 u5 2 kx) (line2 u6 2 kx)
		(setq d1s (rtos d1 2 2)
			d2s (rtos d2 2 2)
			d3s (rtos d3 2 2)
			d4s (rtos d4 2 2)
			d5s (rtos c4ad7 2 2)
			d6s (rtos c4ad8 2 2)
			d7s (rtos c4ad9 2 2)
			d8s (rtos c4ad5 2 2)
			d9s (rtos c4ad6 2 2))		
	(text (strcat "入口宽 " (rtos d1))  (list (car pt0) (- (cadr pt0) 300)) 50 7 0 "序号图层")
	(text (strcat "入口深 " (rtos d2))  (list (car pt0) (- (cadr pt0) 400)) 50 7 0 "序号图层")
	(text (strcat "出口宽 " (rtos d3))  (list (car pt0) (- (cadr pt0) 500)) 50 7 0 "序号图层")
  (text (strcat "出口深 " (rtos d4))  (list (car pt0) (- (cadr pt0) 600)) 50 7 0 "序号图层")
	(text (strcat "变径长度 " (rtos c4ad7))  (list (car pt0) (- (cadr pt0) 700)) 50 7 0 "序号图层")
  (text (strcat "入口伸量 " (rtos c4ad8))  (list (car pt0) (- (cadr pt0) 800)) 50 7 0 "序号图层")
	(text (strcat "出口伸量 " (rtos c4ad9))  (list (car pt0) (- (cadr pt0) 900)) 50 7 0 "序号图层")
	(text (strcat "宽偏移 " (rtos c4ad5))  (list (car pt0) (- (cadr pt0) 1000)) 50 7 0 "序号图层")
	(text (strcat "深偏移 " (rtos c4ad6))  (list (car pt0) (- (cadr pt0) 1100)) 50 7 0 "序号图层")		
  (text (strcat C4ad0 "/1")  (h-mid (h-mid p3 p4) (h-mid p7 pt0)) 150 1 1 "0")
	(text (strcat C4ad0 "/2")  (h-mid (h-mid o3 o4) (h-mid o7 pt1)) 150 1 1 "0")
	(text (strcat C4ad0 "/3")  (h-mid (h-mid i3 i4) (h-mid i7 pt2)) 150 1 1 "0")
	(text (strcat C4ad0 "/4")  (h-mid (h-mid u3 u4) (h-mid u7 pt3)) 150 1 1 "0")
	(cond ((= c4ad11 0)
 (setq d11 nil))
		    ((= c4ad11 1)
	(progn
	  (setq u8(list (car pt0) (- (cadr pt0) 5000))
          u9(list (+ (car pt0) c4ad1)  (- (cadr pt0) 5000))
	        u10(list (car u9)  (- (cadr u9) c4ad2))
		      u11(list (car u8) (cadr u10)))
		(setq u12(list (+ (car u8) c4ad5) (- (cadr u8) c4ad6))
          u13(list (+ (car u12) c4ad3) (cadr u12))
			    u14(list (car u13) (- (cadr u13)c4ad4))
			    u15(list (car u12)(cadr u14)))
(MK-line3 (list u8 u9 u10 u11 u8) 1 "3中心线层")(MK-line3 (list u12 u13 u14 u15 u12) 7 "序号图层")
(MK-line3 (list u8 u12) 7 "序号图层")(MK-line3 (list u9 u13) 7 "序号图层") (MK-line3 (list u10 u14) 7 "序号图层")(MK-line3 (list u11 u15) 7 "序号图层")
(dim1 u11 u10 1 -100 "m-8")	(dim1 u12 u13 1 -100 "m-8")	(dim1 u11 u15 1 100 "m-8")
(dim1 u9 u10 2 100 "m-8")   (dim1 u12 u15 2 30 "m-8")   (dim1 u8 u12 2 -100 "m-8")
(text "俯视图" (list (- (car u10) (/ c4ad1 2) )  (- (cadr u10) 500)) 300 1 1 "序号图层" )
	))
	((= c4ad11 2)
	(progn
	  (setq u8(list (car pt0) (- (cadr pt0) 5000))
          u9(list (+ (car pt0) c4ad1)  (- (cadr pt0) 5000))
	        u10(list (car u9)  (- (cadr u9) c4ad2))
		      u11(list (car u8) (cadr u10)))
		(setq
			    u15(list (+(car u11)c4ad5) (+(cadr u11) c4ad6))
			    u12(list (car u15) (+(cadr u15) c4ad4))
			    u13(list (+ (car u12) c4ad3) (cadr u12))
			    u14(list (car u13) (- (cadr u13) c4ad4)))
(MK-line3 (list u8 u9 u10 u11 u8) 7 "序号图层")(MK-line3 (list u12 u13 u14 u15 u12) 1 "3中心线层")		
(MK-line3 (list u8 u12) 7 "序号图层")(MK-line3 (list u9 u13) 7 "序号图层") (MK-line3 (list u10 u14) 7 "序号图层")(MK-line3 (list u11 u15) 7 "序号图层")
(dim1 u11 u10 1 -100 "m-8")	(dim1 u12 u13 1 -100 "m-8")	(dim1 u11 u15 1 100 "m-8")
(dim1 u9 u10 2 100 "m-8")   (dim1 u12 u15 2 30 "m-8")   (dim1 u8 u12 2 -100 "m-8")
(text "仰视图" (list (- (car u10) (/ c4ad1 2) )  (- (cadr u10) 500)) 300 1 1 "序号图层" )		
	))			
	)           
  )
(defun test1 (/ *excel* *sheet* *xlapp*  exname pcs pcs1 pt0)
  (vl-load-com)
  ;(setq exname "C:\\Users\\Administrator\\Desktop\\自动生成参数1.xlsx")
	(setq exname "D:\\小辉插件\\标准模板\\自动化生成数据表.xls")
  (setq *excel* (vlax-create-object "excel.application"))
  (setq *xlapp* (vlax-invoke-method (vlax-get-property *excel* 'Workbooks) 'Open exname))
  (vla-put-visible *excel* 0)  ;;显示工作表
  (setq *sheet* (vlax-get-property (vlax-get-property *xlapp* 'Worksheets) 'item "焊接变径"))
	(setq pcs (atof(Ljx-read-excel-text1 "Q" 2 *sheet*)))
	(setq pt0(getpoint "请输入插入的位置："))
	(SETQ pcs1 1)
	    (while	
			
				(> pcs 0)
				(progn
				(setq pcs(- pcs 1))
				(SETQ pcs1(+ pcs1 1))
				(setq pt0 (list (+ (car pt0) 8000) (cadr pt0)))
			(setq	c4ad0 (itoa(atoi(Ljx-read-excel-text1  "B" PCS1 *sheet*)))
				    c4ad1 (atof(Ljx-read-excel-text1  "C" PCS1 *sheet*))
				    c4ad2 (atof(Ljx-read-excel-text1  "D" PCS1 *sheet*))
				    c4ad3 (atof(Ljx-read-excel-text1  "E" PCS1 *sheet*))
			    	c4ad4 (atof(Ljx-read-excel-text1  "F" PCS1 *sheet*))
				    c4ad5 (atof(Ljx-read-excel-text1  "G" PCS1 *sheet*))
			      c4ad6 (atof(Ljx-read-excel-text1  "H" PCS1 *sheet*))
		        c4ad7 (atof(Ljx-read-excel-text1  "I" PCS1 *sheet*))
		        c4ad8 (atof(Ljx-read-excel-text1  "J" PCS1 *sheet*))
		        c4ad9 (atof(Ljx-read-excel-text1  "K" PCS1 *sheet*))	
				)
				(c4 pt0)	
			))   
  (vlax-invoke-method (vlax-get-property *excel* "ActiveWorkbook") 'Close 0)
  (vlax-invoke-method *excel* 'QUIT)
  (vlax-release-object *sheet*) 
  (vlax-release-object *xlapp*)
)
	
	
	
	
	
	
	(defun Ljx-read-excel-data1 (vv hor sh) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2))
)

;;;;;读取数excel数据函数输出text格式
(defun Ljx-read-excel-text1 (vv hor sh /  ru) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vl-princ-to-string (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2)))
)
(defun ljx-vlxls-get-range-value1 ( sheet rangeid / range value valuelist )
  (setq range (vlax-get-property sheet 'Range rangeid))
  (setq value (vlax-get-property range 'Value2))
  (cond
    ((= (vlax-variant-type value)  8204);;;为数组时，即为区域;
        (progn
          (setq value (vlax-safearray->list(vlax-variant-value value)))
          (setq valuelist (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) value))
        )
    )
    ( T;;;;为单个单元格;
      (setq valuelist (vlax-variant-value value))
    )
  );;;;cond
  valuelist
)	
	;;---------开始写面板调用函数
	(if (/= 'str (type c4ad0))
      (progn (setq c4ad0 "1")
(setq c4ad1 600)(setq c4ad2 500)(setq c4ad3 400)(setq c4ad4 450)
      (setq c4ad5 50)(setq c4ad6 25)(setq c4ad7 447)(setq c4ad8 48.5)(setq c4ad9 48.5)(setq c4ad10 1.5)(setq c4ad12 1)
			))
	
	(h-read1  "c4");读取注册表的数据
	(defun getdata1() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
    (setq c4ad0  (get_tile "d0"))
    (setq c4ad1  (atof(get_tile "d1")))
    (setq c4ad2  (atof(get_tile "d2")))
    (setq c4ad3  (atof(get_tile "d3")))
    (setq c4ad4  (atof(get_tile "d4")))
    (setq c4ad5  (atof(get_tile "d5")))
    (setq c4ad6  (atof(get_tile "d6")))
    (setq c4ad7  (atof(get_tile "d7")))
    (setq c4ad8  (atof(get_tile "d8")))
		(setq c4ad9  (atof(get_tile "d9")))
		(setq c4ad10 (atof(get_tile "d10")))
		(setq c4ad11 (atoi(get_tile "d11")))
		(setq c4ad12 (atof(get_tile "d12")))
	)
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "矩形变径一键展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	 (set_tile "d0" c4ad0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos c4ad1 2 2));
  (set_tile "d2" (rtos c4ad2 2 2));
  (set_tile "d3" (rtos c4ad3 2 2));
  (set_tile "d4" (rtos c4ad4 2 2));
  (set_tile "d5" (rtos c4ad5 2 2));
  (set_tile "d6" (rtos c4ad6 2 2));
	(set_tile "d7" (rtos c4ad7 2 2));
	(set_tile "d8" (rtos c4ad8 2 2));
	(set_tile "d9" (rtos c4ad9 2 2));
  (set_tile "d10" (rtos c4ad10 2 2));厚度
	(if (/= c4ad11 nil)
  (set_tile "d11" (rtos c4ad11 2 2)));辅助视图
	(set_tile "d12" (rtos c4ad12 2 2));
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
	(action_tile "EL1" "(getdata1)(done_dialog 3)")
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "1、重构代码，变量存储注册表，提升执行速度
2、增加读取EXCEL批量生成功能
3、增加辅助视图功能
4、编号位置校准(永远处于中心位置，不会出现偏量太大导致编号跑偏)
5、增加板材厚度功能")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint "请选择图形插入点"))
				(c4 pt0)))
	 ((= re 3);确认
				(test1))	
	)		
	(h-save1  '(c4ad0 c4ad1 c4ad2 c4ad3 c4ad4 c4ad5 c4ad6  c4ad tsl c4ad7 c4ad8 c4ad9 c4ad10 c4ad11 c4ad12) "c4");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;方弯头展开 C5
(defun c:c5(/ c5 c5bd1 c5bd2 c5bd3 c5bd4 c5bd5 c5bd6 c5bd7 dcl_file dcl_id getdata1 getdata2 make-dclcs pt0 re)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "矩形弯头一键展开:dialog"
				 "{ // start dcl"
				 "label = \"矩形弯头一键展开\";"
			         ":row{"
				 ":column{"
				 ":edit_box{label=\"管件序号为  (个)：\";key=\"d1\"; edit_width=7;}"
				 ":edit_box{label=\"弯头宽度为  (mm)：\";key=\"d2\"; edit_width=7;}"
				 ":edit_box{label=\"弯头深度为  (mm)：\";key=\"d3\"; edit_width=7;}"
			         ":edit_box{label=\"弯头角度为  (mm)：\";key=\"d4\"; is_tab_stop=false; edit_width=7;}"
			  	 ":edit_box{label=\"弯头上伸量为(mm)：\";key=\"d5\"; edit_width=7;}"
			         ":edit_box{label=\"弯头下伸量为(mm)：\";key=\"d6\"; edit_width=7;}"
			         ":edit_box{label=\"弯头内R为   (mm)：\";key=\"d7\"; edit_width=7;}"
			         ":popup_list{label=\"板材厚度为(mm)：\";key=\"d8\";list=\"1.5t\\n0.8t\\n1.0t\\n1.2t\\n2.0t\\n3.0t\\n4.0t\\n5.0t\"; edit_width=7;is_tab_stop=false;}"
			      
				 "}} "			 				
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\";
				 is_default=true;height=2;} "	":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;height=2;}" ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;height=2;}" "} "
			  
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 ))
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c5 (pt1 / a a1 d1s d2 d2s d3 d3s d4s d5s d6s d7s d8 d9 hc1 hc2 p1 p10 p11 p12 p13 p14 p15 p16 p2 p21 p22 p23 p24 p25 p26 p27 p28 p29 p3 p30 p4 p5 p6 p7 p8 p9 pt0 pt2 pt3 x1 zb)
	(cond ((= c5bd8 0)
       (setq d8 1.5)) ((= c5bd8 1) (setq d8 0.8))
 ((= c5bd8 2) (setq d8 1.0)) ((= c5bd8 3) (setq d8 1.2))
 ((= c5bd8 4) (setq d8 2.0)) ((= c5bd8 5) (setq d8 3.0))((= c5bd8 6) (setq d8 4.0))((= c5bd8 7) (setq d8 5.0)))
(cond ((= c5bd9 0)
       (setq zb 1)) ((= c5bd9 1) (setq zb 2))
 ((= c5bd9 2) (setq zb 3)) ((= c5bd9 3) (setq zb 4)))
  (setq d2 (- c5bd2 (* 2 d8)));对宽度和深度再赋值
  (setq d3 (- c5bd3 (* 2 d8)))
  (setq d9 (+ c5bd7 d2));弯头外R
	   
 (setq a(* c5bd4 (/ pi 180)));a 展开料夹角弧度a=pi*d1/R1;这里直接将角度转成弧度系数了，弧度=角度× (π ÷180)
 (setq a1(* (+ c5bd4 90) (/ pi 180)));a1为弯头伸量的方向
 (setq pt0(list (- (car pt1) 1000) (+ (cadr pt1) 500)))
 (setq p1(list (car pt0) (+ (cadr pt0) c5bd6)))
 (setq p2(list (- (car p1) c5bd7) (cadr p1)));中心点的位置
 (setq p3(list (+ (car p2) (* c5bd7 (cos a))) (+ (cadr p2) (* c5bd7 (sin a)))))
 (setq p6(list (+ (car p2) (* d9 (cos a))) (+ (cadr p2) (* d9 (sin a)))));弯头外R
 (setq p4(polar p3 a1 c5bd5))
 (setq p5(polar p4 a d2))
 (setq p8(polar pt0 0 d2))
 (setq p7(list (car p8) (+ (cadr p8) c5bd6)))
 (MK-line1 (list p7 p8 pt0 p1))
 (mk-arc p2 p1 p3) (mk-arc p2 p7 p6)
 
 (MK-line1 (list p3 p4 p5 p6))
 (dim1 p1 pt0 2 -50 "m-8") (dim1 p1 p2 1 0 "m-8")(dim1 pt0 p8 1 -150 "m-8")(dal p5 p6 (list(car (h-mid p5 p6)) (+ (cadr (h-mid p5 p6) )50)))
 (if (<= c5bd8 90)
	(setq pt1 (list (- (car p4) 500) (- (cadr pt0) 250)))
	(setq pt1(list (- (car p5) 500) (- (cadr pt0) 250))))       
  (setq pt2(list (+ (car p8) 250) (+ (cadr p5) 800)))
  (setq pt3(list (car pt2) (- (cadr pt2) 150)))
  (setq x1(ssget "_w" pt2 pt1))
  (command "mirror" x1 "" pt2 pt3 "n")
  (setq hc1(/ (* c5bd4 pi (- c5bd7 (/ D8 2))) 180))
  (setq hc2(/ (* c5bd4 pi (+ D9 (/ D8 2))) 180))
  (setq p9(list (car pt0) (- (cadr pt0) 400)))
  (setq p10(list (car p9) (- (cadr p9) c5bd5)))
  (setq p11(list (car p9) (- (cadr p10) hc1)))
  (setq p12(list (car p9) (- (cadr p11) c5bd6)))
  (setq p13(list (+ (car p9) d3) (cadr p12)))
  (setq p14(list (car p13) (cadr p11)))
  (setq p15(list (car p13) (cadr p10)))
  (setq p16(list (car p13) (cadr p9)))
	(MK-line (list p9 p10 p11 p12 p13 p14 p15 p16))
	(line1 p10 1) (line1 p11 1) (line1 p14 2)(line1 p15 2)
  (setq p21(list (+ (car p16) 650) (cadr p16)))
  (setq p22(list (car p21) (- (cadr p21) c5bd5)))
  (setq p23(list (car p21) (- (cadr p22) hc2)))
  (setq p24(list (car p21) (- (cadr p23) c5bd6)))
  (setq p25(list (+ (car p21) d3) (cadr p24)))
  (setq p26(list (car p25) (cadr p23)))
  (setq p27(list (car p25) (cadr p22)))
  (setq p28(list (car p25) (cadr p21)))
	(MK-line (list p21 p22 p23 p24 p25 p26 p27 p28))
	(line1 p22 1) (line1 p23 1) (line1 p26 2)(line1 p27 2)		
  (setvar "dimtix" 1)(command "dimlinear" p9 p10 "@-50,50")
	(dim1 p10 p11 2 -50 "m-8")(dim1 p9 p16 1 50 "m-8")(dim1 p13 p14 2 50 "m-8")
	(dim1 p21 p28 1 50 "m-8")(dim1 p22 p23 2 -50 "m-8")
  (setq d1s(rtos c5bd2 2 2))
  (setq d2s(rtos c5bd3 2 2))
  (setq d3s(rtos c5bd4 2 2))
  (setq d4s(rtos c5bd5 2 2))
  (setq d5s(rtos c5bd6 2 2))
  (setq d6s(rtos c5bd7 2 2))
  (setq d7s(rtos d8 2 2))
	(text (strcat "弯头的宽度 " d1s) (list (car p12) (- (cadr p12) 300))  50 7 0 "序号图层" )
	(text (strcat "弯头的深度 " d2s) (list (car p12) (- (cadr p12) 400))  50 7 0 "序号图层" )	
	(text (strcat "弯头的角度 " d3s) (list (car p12) (- (cadr p12) 500))  50 7 0 "序号图层" )					
	(text (strcat "弯头的上伸量 " d4s) (list (car p12) (- (cadr p12) 600))  50 7 0 "序号图层" )
	(text (strcat "弯头的下伸量 " d5s) (list (car p12) (- (cadr p12) 700))  50 7 0 "序号图层" )
	(text (strcat "弯头的内R " d6s) (list (car p12) (- (cadr p12) 800))  50 7 0 "序号图层" )
	(text (strcat "板材的厚度 " d7s "mm") (list (car p12) (- (cadr p12) 900))  50 7 0 "序号图层" )				
	(if (/= c5bd4 90)
      (text "PS:注意角度不为90度,增加直段扣除内R不能按照常规标准" (list (car p12) (- (cadr p12) 1000))  50 2 0 "序号图层" ))		
	(setq p29	(h-mid	(get-arc-mid p2 p1 p3) (get-arc-mid p2 p7 p6));第一个中心点(两个圆弧中心的中点)
		    p30 (list (+ (car p29) (* (- (car pt2) (car p29)) 2)) (cadr p29) ))		
	(text (strcat c5bd1 "/1") p29  150 1 1 "0" )	
	(text (strcat c5bd1 "/2") p30  150 1 1 "0" )
	(text (strcat c5bd1 "/3") (h-mid(h-mid p9 p16)(h-mid p12 p13))  150 1 1 "0" )
	(text (strcat c5bd1 "/4") (h-mid(h-mid p21 p28)(h-mid p24 p25))  150 1 1 "0")
	)
	;;---------开始写面板调用函数
	(if (/= 'str (type c5bd1))
      (progn (setq c5bd1 "1")
(setq c5bd2 500)(setq c5bd3 300)(setq c5bd4 90)(setq c5bd5 48.5)
          (setq c5bd6 48.5)(setq c5bd7 151.5)))
	
	(h-read1 "c5");读取注册表的数据
	(defun getdata2() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
    (setq c5bd1  (get_tile "d1"))
    (setq c5bd2  (atof(get_tile "d2")))
    (setq c5bd3  (atof(get_tile "d3")))
    (setq c5bd4  (atof(get_tile "d4")))
    (setq c5bd5  (atof(get_tile "d5")))
    (setq c5bd6  (atof(get_tile "d6")))
    (setq c5bd7  (atof(get_tile "d7")))
    (setq c5bd8  (atoi(get_tile "d8")))
    
	)
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "矩形弯头一键展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	
  (set_tile "d1" c5bd1 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d2" (rtos c5bd2 2 2));宽度
  (set_tile "d3" (rtos c5bd3 2 2));深度
  (set_tile "d4" (rtos c5bd4 2 2));角度
  (set_tile "d5" (rtos c5bd5 2 2));ddi 
  (set_tile "d6" (rtos c5bd6 2 2));下伸量
  (set_tile "d7" (rtos c5bd7 2 2));内R
  (if (/= c5bd8 nil)
  (set_tile "d8" (rtos c5bd8 2 2)));厚度
 ;将对应key的全局变量传递给控件
  (mode_tile "d1" 2);设置d1为焦点
	(action_tile "cancel" "(getdata2)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata2)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata2)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "1、重构代码，提升执行速度
2、编号位置校准中心
")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint "请选择图形插入点"))
				(c5 pt0)
				
			))	
	)	
	
	(h-save1 '(c5bd1 c5bd2 c5bd3 c5bd4 c5bd5 c5bd6 c5bd7 c5bd8 c5bd9) "c5");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;弯头接变径展开 C5A
(defun c:c5a(/ c512s d10s d12 d13 d1s d2s d3s d4s d5s d6s d7s d8s d9s hc1 hc2 make_wtjbj_dcl p1 p10 p10s p11 p11s p12 p12s p13 p13s p14 p14s p15 p15s p16 p16s p17 p17s p18 p18s p19 p19s p1s p2 p20 p20s p21 p21s p22 p22s p23 p23s p24 p24s p25 p26 p27 p28 p29 p2s p3 p30 p31 p32 p33 p34 p35 p36 p3s p4 p4s p5 p5s p6 p6s p7 p7s p8 p8s p9 p9s pt0 pt1 pt2 pt3 pt4 w1 x1);弯头接变径一键展开
  (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
(defun make_WTJBJ_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "弯头接变径:dialog { //定义名字为方马口展开的对话框"
 "     label= \"弯头接变径\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"序号         (个)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d12\";//编辑框1的关键字"
  "               mnemonic = \"d12\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头宽       (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头深       (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头上伸量   (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头下伸量   (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头内R      (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径入口宽   (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d7\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	 	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径入口深   (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d8\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	 	 	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径长      (mm)： \"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d9\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
	 	 	 	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径入口伸量 (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d10\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
	 
	 	 	 	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径深偏移  (mm)： \"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d11\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"



	 	 
  


             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-WTJBJ.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
  (setq Keys '( "d12" "d1" "d2" "d4" "d5" "d6" "d7" "d8" "d9" "d10" "d11"  ))
  (if (not c5ad1)
  (progn
  (setq c5ad1 447 c5ad2 447)
  (setq c5ad4 48.5 c5ad5 48.5)
  (setq c5ad6 151.5 c5ad7 447)
  (setq c5ad8 447 c5ad9 498.5)
  (setq c5ad12 1)
  (setq c5ad10 48.5 c5ad11 150);设变量初值
  
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_WTJBJ_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "弯头接变径" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list
	           (rtos c5ad12 2 2) (rtos c5ad1 2 2)
		   (rtos c5ad2 2 2)  (rtos c5ad4 2 2)
		   (rtos c5ad5 2 2)  (rtos c5ad6 2 2)
		   (rtos c5ad7 2 2)  (rtos c5ad8 2 2)
		   (rtos c5ad9 2 2)  (rtos c5ad10 2 2)
		   (rtos c5ad11 2 2)
		   )
    )
    ;设置d1为焦点
    (mode_tile "d12" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c5a\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
  (setq pt0(getpoint"请点击插入的位置:"))
  (setq d3 90)
 ;上面为设定变量程序
 (setq d12(sqrt(+ (* c5ad11 c5ad11) (* (- c5ad9 c5ad10) (- c5ad9 c5ad10)))));此为左嵌板斜边长
 (setq d14(- c5ad9 c5ad10))
 (setq d13(abs (+ (- c5ad2 c5ad8) c5ad11)));深偏移对立长
 (setq hc1(/ (* d3 pi c5ad6) 180));短弧长
 (setq hc2(/ (* d3 pi (+ c5ad6 c5ad1)) 180));长弧长

 ;上面是有设定变量程序计算出的变量程序
(setq p1(list (+ (car pt0) c5ad8) (cadr pt0)))
(setq p2(list (car p1) (+ (cadr p1) c5ad10)))
(setq p3(list (- (car p1) c5ad11) (+ (cadr p2) d14)))
(setq p4(list (car p3) (+ (cadr p3) c5ad5)))
(setq p5(list (car p4) (+ (cadr p4) hc1)))
(setq p6(list (car p5) (+ (cadr p5) c5ad4)))
(setq p7(list (- (car p6) c5ad2) (cadr p6)))
(setq p8(list (car p7) (- (cadr p7) c5ad4)))
(setq p9(list (car p8) (- (cadr p8) hc1)))
(setq p10(list (car p9) (cadr p3)))
(setq p11(list (car pt0) (cadr p2)))
(command "line" pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 "c")
(command "-DIMSTYLE" "R" "m-8")
(command "dimlinear" pt0 p1 "h" "@-50,-150");标注变径深
(command "dimlinear" p2 p3 "h" "@50,-250");深偏量
(setvar "dimtix" 1) ;强制尺寸文本在两尺寸界线之内
(command "dimlinear" p3 p4 "v" "@50,-50");弯头下伸量
(command "dimlinear" p6 p7 "h" "@-50,50");标注弯头深
(command "dimlinear" p5 p6 "v" "@50,-50");标注弯头上伸量
(command "dimlinear" p8 p9 "v" "@-50,50");标注弯头短弧长
(command "dimlinear" p10 pt0 "v" "@-150,50");标注变径长（当入口宽等于出口宽时） 
;上面的为第一块料及其标注数据
(setq p1s(list (- (car p2) 1) (cadr p2)))
(setq p2s(list (- (car p3) 1) (cadr p3)))
(setq p3s(list (- (car p4) 1) (cadr p4)))
(setq p4s(list (- (car p5) 1) (cadr p5)))
(setq p5s(list (+ (car p8) 1) (cadr p8)))
(setq p6s(list (+ (car p9) 1) (cadr p9)))
(setq p7s(list (+ (car p10) 1) (cadr p10)))
(setq p8s(list (+ (car p11) 1) (cadr p11)))
(command "color" "2")
(command "line" p2 p1s "")(command "line" p3 p2s "")(command "line" p4 p3s "")
(command "line" p5 p4s "")(command "line" p8 p5s "")(command "line" p9 p6s "")
(command "line" p10 p7s "")(command "line" p11 p8s "")
(command "color" "7")
;上面为第一块料打点数据
(setq p12(list (+ (car p1) 800) (cadr p1)));定位点
(setq p13(list (car p12) (+ (cadr p12) c5ad10)))
(setq p14(list (+ (car p13) c5ad11) (+ (cadr p13) d14)))
(setq p15(list (car p14) (+ (cadr p14) c5ad5)))
(setq p16(list (car p15) (+ (cadr p15) hc2)))
(setq p17(list (car p16) (+ (cadr p16) c5ad4)))
(setq p18(list (+ (car p17) c5ad2) (cadr p17)))
(setq p19(list (car p18) (- (cadr p18) c5ad4)))
(setq p20(list (car p19) (cadr p15)))
(setq p21(list (car p20) (cadr p14)))
(setq p23(list (+ (car p12) c5ad8) (cadr p12)))
(setq p22(list (car p23) (+ (cadr p23) c5ad10)))		       
(command "line" p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 "c")
(command "dimlinear" p12 p23 "h" "@-50,-150");标注变径深
(command "dimlinear" p22 p21 "h" "@50,-50");深偏量
(command "dimlinear" p15 p16 "v" "@50,-50");标注弯头长弧长
(command "dimlinear" p17 p18 "h" "@-50,50");标注弯头深
;上面为第二块料
(setq p9s(list (+ (car p13) 1) (cadr p13)))
(setq p10s(list (+ (car p14) 1) (cadr p14)))
(setq p11s(list (+ (car p15) 1) (cadr p15)))
(setq p12s(list (+ (car p16) 1) (cadr p16)))
(setq p13s(list (- (car p19) 1) (cadr p19)))
(setq p14s(list (- (car p20) 1) (cadr p20)))
(setq p15s(list (- (car p21) 1) (cadr p21)))
(setq p16s(list (- (car p22) 1) (cadr p22)))
(command "color" "2")
(command "line" p13 p9s "")(command "line" p14 p10s "")
(command "line" p15 p11s "")(command "line" p16 p12s "")
(command "line" p19 p13s "")(command "line" p20 p14s "")
(command "line" p21 p15s "")(command "line" p22 p16s "")
(command "color" "7")
;上面为第二块料打点数据

(setq p24(list (car p17) (+ (cadr p17) 1000)))
(setq p25(list (car p24) (+ (cadr p24) c5ad10)))
(setq p26(list (car p25) (+ (cadr p25) d12)))
(setq p27(list (car p26) (+ (cadr p26) c5ad5)))
(setq p28(list (+ (car p27) c5ad1 c5ad6) (cadr p27)));圆弧圆心
(setq p29(list (car p28) (+ (cadr p28) c5ad1 c5ad6)))
(setq p30(list (+ (car p29) c5ad4) (cadr p29)))
(setq p31(list (car p30) (- (cadr p30) c5ad1)))
(setq p32(list (car p29) (cadr p31)))
(setq p33(list (+ (car p27) c5ad1) (cadr p27)))
(setq p34(list (car p33) (cadr p26)))
(setq p35(list (car p34) (cadr p25)))
(setq p36(list (car p35) (cadr p24)))
(command "line" p24 p25 p26 p27 "")
(command "arc" p29 "c" p28 p27)
(command "line" p29 p30 p31 p32 "")
(command "arc" p32 "c" p28 p33)
(command "line" p33 p34 p35 p36 p24 "")
(command "dimlinear" p24 p36 "h" "@-50,-150");标注变径宽
(command "dimlinear" p36 p35 "v" "@50,-50");变径下伸量
(command "dimlinear" p33 p34 "v" "@50,-50");标注弯头下伸量
(command "dimlinear" p33 p28 "h" "@50,50");标注弯头
(command "dimlinear" p31 p30 "v" "@150,50");标注弯头宽
;上面为第三块料
(setq p17s(list (+ (car p25) 1) (cadr p25)))
(setq p18s(list (+ (car p26) 1) (cadr p26)))
(setq p19s(list (+ (car p27) 1) (cadr p27)))
(setq p20s(list (car p29) (- (cadr p29) 1)))
(setq p21s(list (car p32) (+ (cadr p32) 1)))
(setq p22s(list (- (car p33) 1) (cadr p33)))
(setq p23s(list (- (car p34) 1) (cadr p34)))
(setq p24s(list (- (car p35) 1) (cadr p35)))
(command "color" "2")
(command "line" p25 p17s "")(command "line" p26 p18s "")
(command "line" p27 p19s "")(command "line" p29 p20s "")
(command "line" p32 p21s "")(command "line" p33 p22s "")
(command "line" p34 p23s "")(command "line" p35 p24s "")
(command "color" "7")
;上面为第三块料打点数据


(setq pt1(list (+ (car p30) 300) (+ (cadr p30) 300)));框选点1
(setq pt2(list (- (car p24) 250) (- (cadr p24) 250)));框选点2
(setq pt3(list (- (car p24) 400) (cadr p24)));镜像点1 
(setq pt4(list (car pt3) (+ (cadr p24) 100)));镜像点2
(setq x1(ssget "_w" pt2 pt1))
(command "mirror" x1 "" pt3 pt4 "n")
;上面为第四片料
(setq c512s(rtos c5ad12 2 2))


  (setq d1s(rtos c5ad1 2 2))
  (setq d2s(rtos c5ad2 2 2)) 
  (setq d3s(rtos c5ad4 2 2))
  (setq d4s(rtos c5ad5 2 2))
  (setq d5s(rtos c5ad6 2 2))
  (setq d6s(rtos c5ad7 2 2)) 
  (setq d7s(rtos c5ad8 2 2))
  (setq d8s(rtos c5ad9 2 2))
  (setq d9s(rtos c5ad10 2 2)) 
  (setq d10s(rtos c5ad11 2 2))
  (command "color" "7")
  (command "layer" "S" "序号图层" "")
  (command "text" "m" (list (car pt0) (- (cadr pt0) 300)) 50 0 (strcat "弯头宽 " d1s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 400)) 50 0 (strcat "弯头深 " d2s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 500)) 50 0 (strcat "弯头上伸量 " d3s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 600)) 50 0 (strcat "弯头下伸量 " d4s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 700)) 50 0 (strcat "弯头内R " d5s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 800)) 50 0 (strcat "变径入口宽 " d6s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 900)) 50 0 (strcat "变径入口深 " d7s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 1000)) 50 0 (strcat "变径长 " d8s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 1100)) 50 0 (strcat "变径入口伸量 " d9s))
  (command "text" "m" (list (car pt0) (- (cadr pt0) 1200)) 50 0 (strcat "变径深偏移 " d10s))

  (command "layer" "S" "0" "")


  

  (command "color" 1)
  (setq w1(list (/ (+ (car p27) (car p33)) 2) (/ (+ (cadr p27) (cadr p33)) 2)))
  (command "text" "m" (list (- (car w1) (* (+ (/ c5ad1 2) 400) 2)) (cadr w1)) 100 0(strcat c512s "/1"));序号标注1
  (command "text" "m" (list (/ (+ (car p4) (car p9)) 2) (/ (+ (cadr p4) (cadr p9)) 2)) 100 0(strcat c512s "/3"));序号标注3
  (command "text" "m" (list (/ (+ (car p15) (car p20)) 2) (/ (+ (cadr p15) (cadr p20)) 2)) 100 0(strcat c512s "/4"));序号标注4
  (command "text" "m" (list (/ (+ (car p27) (car p33)) 2) (/ (+ (cadr p27) (cadr p33)) 2)) 100 0(strcat c512s "/2"));序号标注2
  (command "color" 7)))
  


  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
  (princ) ;静默退出

 )

;方马口展开 C6
(defun c:c6(/ c6 c6d1 c6d2 c6d3 c6d4 c6d5 c6d6 dcl_file dcl_id getdata1 make-dclcs pt0 re)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "方马口展开:dialog"
				 "{ // start dcl"
				 "label = \"方马口展开\";"	
         ":row{"
         ":boxed_column{label = \"交互参数\";"			 
				 ":edit_box{label=\"马口长(mm):\";key=\"d1\";}";编辑框
				 ":edit_box{label=\"马口宽(mm):\";key=\"d2\";}";编辑框
				 ":edit_box{label=\"偏移量(mm):\";key=\"d3\";}";编辑框
				 ":edit_box{label=\"马口高(mm):\";key=\"d4\";}";编辑框
				 ":edit_box{label=\"上伸量(mm):\";key=\"d5\";}}";编辑框
				 ":boxed_column{label = \"设置参数\";"
				 ":edit_box{label=\"板材厚度:\";key=\"d6\";is_tab_stop=false;}";板材板厚
         ":spacer{height = 8;}}}";填补剩余间隙，使一二两列保持平行
				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c6 (p0 / d1s d2s d3s d4s d6 ds p1 p10 p11 p12 p13 p14 p15 p16 p2 p3 p4 p5 p6 p7 p8 p9 pc pc1)
	(setq d6 c6d6)
	
	(setq p1(list (+ (car p0) (- c6d1 (* d6 2))) (cadr p0)))
  (setq p2(list (+ (car p1) (- c6d2 (* d6 2))) (cadr p0)))
  (setq p3(list (+ (car p2) (- c6d1 (* d6 2))) (cadr p0)))      
  (setq p4(list (car p3) (- (cadr p3) c6d5)))
  (setq p5(list (+ (car p4) c6d3) (- (cadr p4) (- c6d4 c6d5))))
  (setq p6(list (- (car p5) (+ (- c6d1 (* d6 2)) c6d3)) (cadr p5)))
  (setq p7(list (- (car p6) (- c6d2 (* d6 2))) (cadr p5)))
  (setq p8(list (- (car p7) (+ (- c6d1 (* d6 2)) c6d3)) (cadr p5)))
  (setq p9(list (+ (car p8) c6d3) (cadr p4)))
  (setq p10(sqrt (+ (* c6d3 c6d3) (* (- c6d4 c6d5) (- c6d4 c6d5)))))
	(setq ds (/ (* (* d6 2)  (/ pi (angle p4 p5) )) 4))
  (setq p11(list (+ (car p5) 300) (cadr p5)))
  (setq p12(list (car p11) (+ (cadr p11) (- p10 ds))))
  (setq p13(list (car p12) (+ (cadr p12) (- c6d5 ds))))
  (setq p14(list (+ (car p13) (- c6d2 (* d6 2))) (cadr p13)))
  (setq p15(list (car p14) (cadr p12)))
  (setq p16(list (car p14) (cadr p11)))
  (MK-line (list p0 p1 p2 p3 p4 p5 p6 p7 p8 p9))
	(MK-line (list p11 p12 p13 p14 p15 p16))
	(line1 p1 4)(line1 p2 4) (line1 p6 3) (line1 p7 3) (line1 p12 1) (line1 p15 2)
	(dim1 p1 p2 1 50 "m-8")(dim1 p2 p3 1 50 "m-8") (dim1 p0 p8 1 -50 "m-8") 
	(dim1 p3 p5 2 150 "m-8") (dim1 p5 p6 1 -130 "m-8") (dim1 p11 p12 2 50 "m-8") 
  (dim1 p13 p14 1 -50 "m-8") (dim1 p14 p15 2 50 "m-8")
  (setq d1s(rtos c6d1 2 2))
  (setq d2s(rtos c6d2 2 2)) 
  (setq d3s(rtos c6d3 2 2))
  (setq d4s(rtos c6d4 2 2))
  (text (strcat (rtos c6d1) "*" (rtos c6d2) "/1")  (h-mid (h-mid p1 p2) (h-mid p7 p6)) 50 1 1 "0")
  (text (strcat (rtos c6d1) "*" (rtos c6d2) "/2")  (h-mid (h-mid p13 p14) (h-mid p11 p16)) 50 1 1 "0")
	(text (strcat "马口长度 " (rtos c6d1))  (list (car p7) (- (cadr p7) 300)) 50 7 0 "序号图层")
	(text (strcat "马口宽度 " (rtos c6d2))  (list (car p7) (- (cadr p7) 400)) 50 7 0 "序号图层")	
	(text (strcat "马口偏移 " (rtos c6d3))  (list (car p7) (- (cadr p7) 500)) 50 7 0 "序号图层")	
	(text (strcat "马口高度 " (rtos c6d4))  (list (car p7) (- (cadr p7) 600)) 50 7 0 "序号图层")
	)
	;;---------开始写面板调用函数
	(if (not c6d1)
  (progn
  (setq c6d1 500 c6d2 300)
  (SETQ c6d3 100 c6d4 148.5)
  (setq c6d5 48.5)(setq c6d6 1.5);设变量初值
  ))
	
	(h-read1  "c6");读取注册表的数据
	(defun getdata1()
		(setq 
			c6d1 (atof (get_tile "d1"))
			c6d2 (atof (get_tile "d2"))
			c6d3 (atof (get_tile "d3"))
			c6d4 (atof (get_tile "d4"))
			c6d5 (atof (get_tile "d5"))
			c6d6 (atof (get_tile "d6"))
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "方马口展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
  (set_tile "d1" (rtos c6d1 2 2))
  (set_tile "d2" (rtos c6d2 2 2))
  (set_tile "d3" (rtos c6d3 2 2))
	(set_tile "d4" (rtos c6d4 2 2 ))
	(set_tile "d5" (rtos c6d5 2 2 ))
	(set_tile "d6" (rtos c6d6 2 2 ))
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "1.侧边料展开按照中径模拟计算
2.重构代码,提升速度")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint "请选择图形插入点"))
				(c6 pt0)
				
			))	
	)	
	
	(h-save1  '(c6d1 c6d2 c6d3 c6d4 c6d5 c6d6) "c6");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

(defun c:c7s(/ c7q c7r cdat dcl_file dcl_id getdata2 ljx-read-excel-data1 ljx-read-excel-text1 ljx-vlxls-get-range-value1 make-dclcs pt0 re ssd0 ssd1 ssd10  ssd2 ssd3 ssd4 ssd5 ssd6 ssd7 ssd8 ssd9 test1) ;变径一键展开绘制
	(setq cdat (atoi (rtos (getvar "cdate"))))
 (if (<= cdat 20270506)
	 (progn
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
   (command "._undo" "_begin")	
(defun make-dclCS  (/ lst_str str file f );;面板的界面显示dcl
		(setq lst_str
			'(
				 "底平中变变径三通:dialog"
				 "{ // start dcl"
				 "label = \"底平中变变径三通\";initial_focus=d0;"        
			         ":row{"
				 ":column{label=\"数据\";"
				 ":edit_box{label=\"序号    (个)：\";key=\"d0\"; edit_width=7;}"
				 ":edit_box{label=\"主管长  (mm)：\";key=\"d1\"; edit_width=7;}"
				 ":edit_box{label=\"主管宽  (mm)：\";key=\"d2\"; edit_width=7;}"
			   ":edit_box{label=\"变径长  (mm)：\";key=\"d3\"; edit_width=7;}"
			   ":edit_box{label=\"变径宽  (mm)：\";key=\"d4\"; edit_width=7;}"
			   ":edit_box{label=\"马口长  (mm)：\";key=\"d5\"; edit_width=7;}"
			   ":edit_box{label=\"马口宽  (mm)：\";key=\"d6\"; edit_width=7;}"
				 ":edit_box{label=\"马口高  (mm)：\";key=\"d7\"; edit_width=7;}"
				 ":edit_box{label=\"马口偏量(mm)：\";key=\"d8\"; edit_width=7;}"
				 ":edit_box{label=\"马口距边(mm)：\";key=\"d9\"; edit_width=7;}"
				 ":edit_box{label=\"总体长度(mm)：\";key=\"d10\"; edit_width=7;}}"
				 ":column{label=\"参数\";"
				 ":popup_list{label=\"变径形式  \";key=\"d11\";list=\"底平中变\\n底平侧平\"; edit_width=9;is_tab_stop=false;}"
				 ":popup_list{label=\"横向分料：  \";key=\"d12\";list=\"1219\\n1500\"; edit_width=9;is_tab_stop=false;}"
				 ":popup_list{label=\"纵向分料：  \";key=\"d12/\";list=\"1500\\n1219\"; edit_width=9;is_tab_stop=false;}"
				 ":edit_box{label=\"风管厚度(mm)：\";key=\"d13\";edit_width=9;is_tab_stop=false;}"
				 ":edit_box{label=\"变径长度(mm)：\";key=\"d14\"; edit_width=9;is_tab_stop=false;}"
				 ":edit_box{label=\"起步长度(mm)：\";key=\"d15\"; edit_width=9;is_tab_stop=false;}"
         ":edit_box{label=\"刻线长度(mm)：\";key=\"d16\"; edit_width=9;is_tab_stop=false;}"
			   ":button {label=\"读EXCEL数据\"; key = \"EL1\";is_tab_stop=false;}"
         " :spacer{height = 2;}}}"
				                          				 				
				 ":row{"":button{is_default= true;label=\"确定(&Q)\";key=\"accept\";
				 height=2;} "	":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;height=2;}" ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;height=2;}" "} "
			  
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 )		      
		)
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		file
	)
(defun c7r(pt0 / bj_l bj1 bj2 c6r c7cd1 c7cd10 c7cd2 c7cd3 c7cd4 c7cd5 c7cd6 c7cd7 c7cd8 c7cd9 d10 d11 d13 d14 d15 d16 fl kx l1 t1 t2 t3 ts1 zhiguan zhu2) ;底平中变焊接变径三通
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
  (setq t1 ssd13);ssd13为厚度
  (setq kx ssd16);SSD16为刻线长度
	(setq BJ_L ssd14);SSD14为变径长度
	;C6R为马口子函数
	(defun c6r(x1 x2 x3 x4 x5 x6 x7 / kx p1 p10 p11 p12 p13 p14 p15 p16 p2 p3 p4 p5 p6 p7 p8 p9 );x1为插入点，x2为马口长，x3为马口宽，x4为偏移量，x5 为马口高，x6为上伸量，x7为板厚
		(setvar "osmode" 0)
		(setq p1 (list (+ (car x1) (- x2 (* 2 x7))) (cadr x1))
      p2 (list (+ (car p1) (- x3 (* 2 x7))) (cadr x1))
      p3 (list (+ (car p2) (- x2 (* 2 x7))) (cadr x1))
      p4 (list (car p3) (- (cadr p3) x6))
      p5 (list (+ (car p4) x4) (- (cadr p4) (- x5 x6)))
      p6 (list (- (car p5) (+ (- x2 3) x4)) (cadr p5))
      p7 (list (- (car p6) (- x3 3)) (cadr p5))
      p8 (list (- (car p7) (+ (- x2 3) x4)) (cadr p5))
      p9 (list (+ (car p8) x4) (cadr p4))
      p10 (sqrt (+ (* x4 x4) (* (- x5 x6) (- x5 x6))))
      p11 (list (+ (car p5) 300) (cadr p5))
      p12 (list (car p11) (+ (cadr p11) p10))
      p13 (list (car p12) (+ (cadr p12) x6))
      p14 (list (+ (car p13) (- x3 (* 2 x7))) (cadr p13))
      p15 (list (car p14) (cadr p12))
      p16 (list (car p14) (cadr p11))
			kx 1    ;定义刻线长度
		)	
		(MK-line (list x1 p1 p2 p3 p4 p5 p6 p7 p8 p9))
		(MK-line (list p11 p12 p13 p14 p15 p16))
		(line2 p1 4 kx) (line2 p2 4 kx)  (line2 p6 3 kx)(line2 p7 3 kx)(line2 p12 1 kx) (line2 p15 2 kx)
		(dim1 p1 p2 1 10 "m-5")(dim1 p2 p3 1 10 "m-5") (dim1 p8 x1 2 -15 "m-5") (dim1 p5 p6 1 -80 "m-5") (dim1 p11 p12 2 -20 "m-5")
		(dim1 p13 p14 1 20 "m-5")(dim1 p14 p15 2 100 "m-5")
		
		(text (strcat ssd0 "/"(rtos xh)) (list (+ (car p1) (/ (- x3 3) 2)) (- (cadr x1) (/ (- x5 3) 2))) 50 1 1 "0")
		(setq xh (1+ xh))
		(text (strcat ssd0 "/"(rtos xh)) (list (+ (car p13) (/ (- x3 3) 2)) (- (cadr p13) 120)) 50 1 1 "0")
		(setq xh (1+ xh))
		(princ))
	
(cond ((= ssd12/ 0)
 (setq t2 1400) (setq FL 1490)) ((= ssd12/ 1) (setq t2 1115) (setq FL 1209))
)	;t2	为纵向分割形式
(cond ((= ssd12 0)
 (setq t3 1219)) ((= ssd12 1) (setq t3 1500))
);t3	为横向分割形式
;基本参数定义
	(setq c7cd1 (- ssd1 (* t1 2))
		c7cd2 (- ssd2 (* t1 2))
		c7cd3 (- ssd3 (* t1 2))
		c7cd4 (- ssd4 (* t1 2))
		c7cd5 (- ssd5 (* t1 2))
		c7cd6 (- ssd6 (* t1 2))
		c7cd7 (- ssd7 t1)
		c7cd8  ssd8 
		c7cd9  ssd9 
		c7cd10 (- ssd10 2))
	
	;根据支口口径确认使用四号角钢或者五号角钢
	(if (or (>= ssd3 1000) (>= ssd4 1000))
		(progn
   (setq d13(sqrt(+ (* (abs (+ (- c7cd3 c7cd1) (/ (- c7cd1 c7cd3) 2))) (abs (+ (- c7cd3 c7cd1) (/ (- c7cd1 c7cd3) 2)))) (* (- BJ_L 60) (- BJ_L 60)))));前嵌板的斜边长
  (setq d10(/ (- c7cd1 c7cd3) 2));宽偏移（D3不能大于D1)否则此函数不成立
  (setq d11(sqrt (+ (* (- c7cd2 c7cd4) (- c7cd2 c7cd4)) (* (- BJ_L 60) (- BJ_L 60)))));变径三通斜边长
			(setq d16(sqrt(+ (* (- c7cd1 c7cd3) (- c7cd1 c7cd3)) (* (- BJ_L 60) (- BJ_L 60)))));前嵌板的斜边长		
	(setq l1 58.5)
					) 
		(progn
	 ;分割线
  (setq d13(sqrt(+ (* (abs (+ (- c7cd3 c7cd1) (/ (- c7cd1 c7cd3) 2))) (abs (+ (- c7cd3 c7cd1) (/ (- c7cd1 c7cd3) 2)))) (* (- BJ_L 50) (- BJ_L 50)))));前嵌板的斜边长
  (setq d10(/ (- c7cd1 c7cd3) 2));宽偏移（D3不能大于D1)否则此函数不成立
  (setq d11(sqrt (+ (* (- c7cd2 c7cd4) (- c7cd2 c7cd4)) (* (- BJ_L 50) (- BJ_L 50)))))
		(setq d16(sqrt(+ (* (- c7cd1 c7cd3) (- c7cd1 c7cd3)) (* (- BJ_L 50) (- BJ_L 50)))));前嵌板的斜边长
			(setq l1 48.5)
		));变径三通斜边长
	(setq d14 (- c7cd1 c7cd3));底平侧平宽偏移
	(setq d15 (- c7cd2 c7cd4));底平侧平深偏移	
	
	
	(if (< ssd15 (/ c7cd2 2))
	   (setq ts1   ssd15)
		 (setq ts1   (/ c7cd2 2))	
			)
  ;上面的为输入的参数
	(if (> ssd10 3900)
	(progn
	
	(defun zhiguan (/ p0x p0y  p10 p10a p10b p11 p12 p13 p14  p1x p1y p2 p2x p2y p3 p4 p5 p6 p7 p8 p9 p9a p9b pg1 pt1x pt2x pt3x pt4x )
		(setq xh 1)
		(setq p1(list (car pt0) (+ (cadr pt0) (- c7cd2 ts1)))
			p2(list (car p1) (+ (cadr p1) c7cd1))
			p3(list (car p2) (+ (cadr p2) c7cd2))
			p4(list (car p3) (+ (cadr p3) c7cd1))
			p5(list (car p4) (+ (cadr p4) ts1))
			p6(list (+ (car p5) (- c7cd10 t2)) (cadr p5))
			p7(list (car p6) (- (cadr p6) ts1))	
		)
		(if (= c7cd1 c7cd6);如果主管长等于马口宽
			(progn ;根据开口大小调整开洞
				(setq p8(list (car p7) (- (cadr p7) 0.5));提前预留0.5mm的折边位置
					p9 (list  (- (car p8) (+ (- (+ c7cd5 c7cd8 (* t1 2)) (- t2 BJ_L) 0.2) c7cd9)) (cadr p8));计算出主管开口位置的X-0.2的点
					p9a(list (car p9) (+ (cadr p9) 0.5));恢复开口位置的y轴
					p9b(list (- (car p9a) 0.2) (cadr p9a));恢复开口位置的x轴
					p10(list (car p9b) (- (cadr p9b)  c7cd6 ));开口位置下面的点
					p10a(list (+ (car p10) 0.2) (cadr p10));下面的点x轴向右偏0.2mm
					p10b(list (car p10a) (+ (cadr p10a) 0.5));下面的点y轴向上偏0.5mm
					p11(list (car p8) (cadr p10b));开口在主管上面右下角
					p12(list (car p11) (- (cadr p11) 0.5))))
			(progn ;正常开洞	   
				(setq p8(list (car p7) (- (cadr p7) (- (/ (- c7cd1 c7cd6) 2) t1)))
					p9(list (- (car p8) (+ (- (+ c7cd5 c7cd8 (* t1 2)) (- t2 BJ_L)) c7cd9)) (cadr p8))
					p10(list (car p9) (- (cadr p9) (+ c7cd6 (* t1 2))))
					p11(list (car p8) (cadr p10))
					p12(list (car p11) (- (cadr p11) (- (/ (- c7cd1 c7cd6) 2) t1))))))
	  ;继续直管定位
		(setq p13(list (car p12) (- (cadr p12) c7cd2))
			p14(list (car p13) (- (cadr p13) c7cd1))
			p15(list (car p14) (cadr pt0))
			pg1(- (+ c7cd5 c7cd8 (* t1 2) c7cd9) (- t2 BJ_L)))	
	 ;PG1变量测试马口位置，大于零则马口位置在主管和支管交错地带，小于零马口位置则在支管处	
		(if
			(> pg1 0)
			(progn
				(if (= c7cd1 c7cd6)
					(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p9a p9b p10 p10a p10b  p11 p12 p13 p14 p15 ))
					(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 ))))
			(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 p12 p13 p14 p15 )))			
		;绘制中心线
		(MK-line3 (list p1 p14) 1 "3中心线层") (MK-line3 (list p2 p13) 1 "3中心线层")
		(MK-line3 (list p3 p12) 1 "3中心线层") (MK-line3 (list p4 p7) 1 "3中心线层")
		(line2 p1 1 kx) (line2 p2 1 kx) (line2 p3 1 kx) (line2 p4 1 kx) (line2 p7 2 kx);打点变色
	 (line2 p12 2 kx)(line2 p13 2 kx) (line2 p14 2 kx)
		;开始基础标注
		(command "-DIMSTYLE" "R" "m-10")
		(setvar "dimtix" 1)		
		(command "DIMLINEAR" PT0 P1  "@-50,0" )
		(dim1 p1 p2 2 -50 "m-10")(dim1 p2 p3 2 -50 "m-10")(dim1 p3 p4 2 -50 "m-10")(dim1 p4 p5 2 -50 "m-10")
		(if
			(> pg1 0)
			(progn
				(if (= c7cd1 c7cd6)
					(progn
						(dim1 p7 p9B 1 50 "m-8")(dim1 p9b p10 2 -50 "m-8")	
					)
					(progn
						(dim1 p8 p9 1 50 "m-8")(dim1 p9 p10 2 -50 "m-8")
					))))
		(dim1 pt0 p5 2 -250 "m-15") (dim1 p5 p6 1 50 "m-15")
				
		;开始分料模拟计算
		(if (> pg1 0)   ;PG1变量测试马口位置，大于零则马口位置在主管和支管交错地带，小于零马口位置则在支管处 
	(progn ;此假设是假设开口在主管上面，这样第一道分料线不能手工下料
  (if (> (- (cadr p5) (cadr p2)) t3);假设表达式，表达当总长减去148.5再减去一个长度大于分料尺寸的话，所要进行的表达式
	 (progn ;大于情况
		(setq p1x(list (car pt0) (- (cadr p5) (- t3 10)))
	        p1y(list (car p15) (cadr p1x)));第一个分料点，往下偏移一个分料尺寸-10
		(MK-line3 (list p1x p1y) 7 "0") (dim1 p6 p1y 2 370 "m-15")
	  (setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (- (cadr p6) (/ (- t3 10) 2))));获取第一道分料线的中心尺寸位置
		(text (strcat ssd0 "/"(rtos xh)) pt1x 250 1 1 "0")
		  (setq xh (1+ xh))
		  (setq p0x p1x)(setq p0y p1y)
		  (while  ;循环表达式，循环手工下料的次数
			 (> (- (cadr p1x)  t3) (+ (cadr pt0) 200))			 
			 (progn
			 (setq p1x(list (car p1x) (- (cadr p1x) t3))
	           p1y(list (car p15) (cadr p1x)))
				(MK-line3 (list p1x p1y) 7 "0") (dim1 p0y p1y 2 370 "m-15")
				(setq pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1y) (/ t3 2))))
				(text "手工下料" pt2x 300 7 1 "0")
				(setq p0x p1x  p0y p1y) 					    
			  ))
		  	
       (if 
			 (> (- (cadr p1x)  t3)  (cadr pt0));假设最后一倒往下分能不能分到最底部的条件公式
			(progn  ;最后一刀不能完全分完
				(setq p2x(list (car pt0) (+ (cadr pt0) 200))
	            p2y(list (car p15) (cadr p2x)))
				(MK-line3 (list p2x p2y) 7 "0")
				(dim1 p1y p2y 2 370 "m-15")(dim1 p2y p15 2 370 "m-15")
				(setq pt3x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) (/ 100 2))))
				(setq pt4x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p2y) (/ (- (cadr p1y) (cadr p2y)) 2))));不能完全分完的情况下，在追加一条分割线，且分割线距离底部至少有110高度
				(text (strcat ssd0 "/"(rtos xh)) pt4x 300 1 1 "0")(setq xh (1+ xh))
				(text (strcat ssd0 "/"(rtos xh)) pt3x 150 1 1 "0")(setq xh (1+ xh))

				
			)
			(progn  ;最后一刀能完全分完
				(dim1 p1y p15 2 370 "m-15")  
				(setq pt3x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) (/ (- (cadr p1y) (cadr pt0)) 2))))
			 (text (strcat ssd0 "/"(rtos xh)) pt3x 250 1 1 "0")(setq xh (1+ xh))
			))			
		 
	 )	
		(progn   ;小于情况
			(if ( < (- (- c7cd2 (* ts1 2)) (- t3 (- (cadr p5) (cadr p2))))  200);当分料可以从下网上分1219的时候
			 (progn   ;不可以的时候
			(setq p1x(list (car pt0) (- (cadr p3) (/ c7cd2 2)))
				    p1y(list (car p15) (cadr p1x)))
			(MK-line3 (list p1x p1y) 7 "0") (dim1 p15 p1y 2  370 "m-15")(dim1 p1y p6 2  370 "m-15")
			(setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1) (/ c7cd1 2))));准备序号中心位置
			(setq pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p3) (/ c7cd1 2))));准备序号中心位置2
			(text (strcat ssd0 "/"(rtos xh)) pt1x 250 1 1 "0")(setq xh (1+ xh))
			(text (strcat ssd0 "/"(rtos xh)) pt2x 250 1 1 "0")(setq xh (1+ xh))			 
			 )
				(progn  ;可以的时候
					(setq p1x(list (car pt0)(+ (cadr pt0) t3))
						    p1y(list (car p15) (cadr p1x)))
					(MK-line3 (list p1x p1y) 7 "0") (dim1 p15 p1y 2  370 "m-15")(dim1 p1y p6 2  370 "m-15")
					(setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) 609.5));标注到中心线的位置
						    pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1y) (/ (- (cadr p5) (cadr p1y)) 2))))
					(text "手工下料" pt1x 300 7 1 "0")
					(text (strcat ssd0 "/"(rtos xh)) pt2x 250 1 1 "0")(setq xh (1+ xh))
				)))))
			 
	(progn ;此假设是假设开口不在主管上，这样第一道分割线可以手工下料
	(if (> (- (cadr p5) (cadr p2))  t3);假设表达式，表达当总长减去148.5再减去一个长度大于分料尺寸的话，所要进行的表达式
	 (progn ;大于情况
		(setq p1x(list (car pt0) (- (cadr p5) t3))
	        p1y(list (car p15) (cadr p1x)));第一个分料点，往下偏移一个分料尺寸
		 (MK-line3 (list p1x p1y) 7 "0")
		 (dim1 p6 p1y 2 370 "m-15")
	  (setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1y) (/ t3 2))));获取第一道分料线的中心尺寸位置
		(text "手工下料" pt1x 300 7 1 "0")
		  (setq p0x p1x)(setq p0y p1y)
		 (while  ;循环表达式，循环手工下料的次数
			 (> (- (cadr p1x)  t3) (+ (cadr pt0) 200))
			 (progn
			 (setq p1x(list (car p1x) (- (cadr p1x) t3))
	           p1y(list (car p15) (cadr p1x)))
				(MK-line3 (list p1x p1y) 7 "0")
				(dim1 p0y p1y 2 370 "M-15")
				(setq pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1y) (/ t3 2))))
				 (text "手工下料" pt2x 300 7 1 "0")
				(setq p0x p1x  p0y p1y) 					    
			  ))
		  (if 
			 (> (- (cadr p1x)  t3)  (cadr pt0));假设最后一倒往下分能不能分到最底部的条件公式
			(progn  ;最后一刀不能完全分完
				(setq p2x(list (car pt0) (+ (cadr pt0) 200))
	            p2y(list (car p15) (cadr p2x)))
				(MK-line3 (list p2x p2y) 7 "0")
				(DIM1 P1Y P2Y 2 370 "m-15")
				(DIM1 P2Y P15 2 370 "m-15")
				(setq pt3x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) (/ 100 2))))
				(setq pt4x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p2y) (/ (- (cadr p1y) (cadr p2y)) 2))));不能完全分完的情况下，在追加一条分割线，且分割线距离底部至少有110高度
				(text (strcat ssd0 "/"(rtos xh)) pt3x 150 1 1 "0")(setq xh (1+ xh))
				(text (strcat ssd0 "/"(rtos xh)) pt4x 300 1 1 "0")(setq xh (1+ xh)))
			(progn  ;最后一刀能完全分完
				(dim1 p1y p15 2 370 "M-15")
				(setq pt3x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) (/ (- (cadr p1y) (cadr pt0)) 2))))
				(text (strcat ssd0 "/"(rtos xh)) pt3x 300 1 1 "0")(setq xh (1+ xh))
			)))
				
		(progn   ;小于情况
			(if ( < (- (- c7cd2 (* ts1 2)) (- t3 (- (cadr p5) (cadr p2))))  200);当分料可以从下往上分1219的时候
			(progn   ;不可以的时候
			(setq p1x(list (car pt0) (- (cadr p3) (/ c7cd2 2)))
				    p1y(list (car p15) (cadr p1x)))
			(MK-line3 (list p1x p1y) 7 "0")
			(dim1 p15 p1y 2 370 "M-15")(dim1 p1y p6 2 370 "M-15")
			(setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1) (/ c7cd1 2))));准备序号中心位置
			(setq pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p3) (/ c7cd1 2))));准备序号中心位置2
			(text (strcat ssd0 "/"(rtos xh)) pt1x 300 1 1 "0")(setq xh (1+ xh))
				(text (strcat ssd0 "/"(rtos xh)) pt2x 300 1 1 "0")(setq xh (1+ xh))
				)
		(progn   ;小于情况
			(if ( < (- (- c7cd2 (* ts1 2)) (- t3 (- (cadr p5) (cadr p2))))  200);当分料可以从下网上分1219的时候
			 (progn   ;不可以的时候
			(setq p1x(list (car pt0) (- (cadr p3) (/ c7cd2 2)))
				    p1y(list (car p15) (cadr p1x)))
			(MK-line3 (list p1x p1y) 7 "0")
			(dim1 p15 p1y 2 370 "M-15")(dim1 p1y p6 2 370 "M-15")
			(setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1) (/ c7cd1 2))));准备序号中心位置
			(setq pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p3) (/ c7cd1 2))));准备序号中心位置2
						(text (strcat ssd0 "/"(rtos xh)) pt1x 300 1 1 "0")(setq xh (1+ xh))
				   (text (strcat ssd0 "/"(rtos xh)) pt2x 300 1 1 "0")(setq xh (1+ xh))
				)	 			 
				(progn  ;可以的时候
					(setq p1x(list (car pt0)(+ (cadr pt0) t3))
						    p1y(list (car p15) (cadr p1x)))
					(MK-line3 (list p1x p1y) 7 "0")
							(dim1 p15 p1y 2 370 "M-15")(dim1 p1y p6 2 370 "M-15")	
					
					(setq pt1x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr pt0) 609.5));标注到中心线的位置
						    pt2x(list (+ (car pt0) (/ (- (car p1y) (car p1x)) 2)) (+ (cadr p1y) (/ (- (cadr p5) (cadr p1y)) 2))))
					(text "手工下料" pt1x 300 7 1 "0")
					(text (strcat ssd0 "/"(rtos xh)) pt2x 300 1 1 "0")(setq xh (1+ xh))
				))))
				
			)
		)	
	)
  ))
		
	(zhiguan)	
  (defun bj1(/ p16 p17 p17/ p18 p19 p19a p19b p20 p20a p20b p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 p40 p41 p42 p43 p44 p45 p46 p46/1 p46/10 p46/11 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p47 p48 p49 p50 pg2 pg3 ps19 ps20 pt1 pt5x pt6x pt7x pt8x)
	(if (= ssd1 ssd3)
	(progn
		(setq p16(list (+ (car p15) 1000) (cadr p15)))
		(setq p17(list (car p16) (+ (cadr p16)(- c7cd1 ts1)))
			    p17/(list (car p17)(+ (cadr p17) c7cd2)))
		(if (= c7cd1 c7cd6);如果主管长等于马口宽
    (progn
			(setq p18(list (car p17/) (+ (cadr p17/) 0.5))
				p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9 0.2)) (cadr p18))
				p19a(list (car p19) (- (cadr p19) 0.5))
				p19b(list (+ (car p19a) 0.2) (cadr p19a))
				p20(list (car p19b) (+ (cadr p19b) c7cd6))
				p20a(list (- (CAR P20) 0.2) (cadr p20))
				p20b(list (car p20a) (- (cadr p20a) 0.5))
				p21(list (car p18) (cadr p20b))
				p22(list (car p21) (+ (cadr p21) 0.5))))
  (progn
   (setq p18(list (car p17/) (+ (cadr p17/) (- (/ (- c7cd1 c7cd6) 2) t1))))
   (setq p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9)) (cadr p18)))
   (setq p20(list (car p19) (+ (cadr p19) (+ c7cd6 (* t1 2)))))
   (setq p21(list (car p18) (cadr p20)))
   (setq p22(list (car p21) (+ (cadr p21) (- (/ (- c7cd1 c7cd6) 2) t1))))))	
	;下面为三通直管只开在支管上面的数据	   
  (setq pg2(+ c7cd5 c7cd8 (* t1 2) c7cd9));开口的总长度
	(if (< pg2 (- t2 BJ_L))
  (progn
	  (if (= c7cd1 c7cd6)
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p17/) pg3) (cadr p17/)))
		(setq p46/1(list (+ (car p46) 0.2) (cadr p17/))
		      p46/2(list (car p46/1)  (+ (cadr p46/1) 0.5))
			    p46/3(list (- (+ (car p46/2) (+ c7cd5 c7cd8 (* t1 2))) 0.4)(cadr p46/2))
					p46/4(list (car p46/3) (cadr p46/1))
			    p46/5(list (+ (car p46/4) 0.2) (cadr p46/4))
			    p46/6(list (car p46/5)(+ (cadr p46/5)c7cd6 ))
			    p46/7(list (car p46/4)(cadr p46/6))
			    p46/8(list (car p46/7)(- (cadr p46/7) 0.5))
			    p46/9(list (car p46/2)(cadr p46/8))
			    p46/10(list (car p46/9)(cadr p46/7))
			    p46/11(list (- (car p46/10) 0.2)(cadr p46/10))))
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p18) pg3) (cadr p18)))
    (setq p47(list (+ (car p46) (+ c7cd5 c7cd8 (* t1 2) )) (cadr p46)))
    (setq p48(list (car p47) (+ (cadr p47) (+ c7cd6 (* t1 2)))))
    (SETQ P49(LIST (car p46) (cadr p48)))))))
    ;P46.47.48/49为开口定位点（开口只在三通面上）
   (setq p23(list (car p22) (+ (cadr p22) c7cd2)))
   (setq p24(list (car p23) (+ (cadr p23) ts1)))
  ;(setq p25(list (car p24) (+ (cadr p24) 148.5)))
   (setq p25(list (+ (car p24) (- t2 BJ_L)) (cadr p24)))
   (setq p26(list (car p25) (cadr p23)));这个要与p23作为第一个打标点，和中心线的连接点
		;(setq p41(list (+ (car p40) (- c7cd2 c7cd4)) (+ (cadr p40) d13)))
	  ;下面为变径部分
   (setq p27(list (+ (car p26) d13) (- (cadr p26) (- c7cd2 c7cd4))));标记,变径打标点
	 (setq p28(list (+ (car p27) l1) (cadr p27)))
   (setq p29(list (car p28) (- (cadr p28) c7cd4)));第二个打标点，这个点的位置与p22连接作为第二个打标点
	 (setq p30(list (car p29) (- (cadr p29)c7cd3)));第三个打标点
   (setq p31(list (car p30) (-(cadr p30)c7cd4)));第四个个打标点
	 (setq p32(list (car p27)(cadr p31)))
	 (setq p33(list (car p25)(cadr p17)))
	 (setq p34(list (car p33)(cadr p16)))
  (if (< pg2 (- t2 BJ_L))
  (progn
		(MK-line (list p16 p17 p17/ p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34  ))
		(if (= c7cd1 c7cd6)
			(progn
		(MK-line (list p46 p46/1 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p46/10 p46/11 )))
			(progn
		(MK-line (list p46 p47 p48 p49 )))))
		
    
  (progn
 (if (= c7cd1 c7cd6)
   
	 (MK-line (list p16 p17 p17/ p18  p19  p19a p19b p20 p20a p20b p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 ))
	 (MK-line (list p16 p17 p17/ p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34  ))
)))

	;		;绘制中心线
	(entmake (list '(0 . "LINE") (cons 10 p17) (cons 11 p33) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p17/) (cons 11 p30) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p22) (cons 11 p29) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p23) (cons 11 p26) (cons 62 1) (cons 8 "3中心线层")))
  (line2 p17 1 kx)(line2 p17/ 1 kx)(line2 p22 1 kx) (line2 p23 1 kx) (line2 p26 2 kx)(line2 p29 2 kx)(line2 p30 2 kx)
  (line2 p27 4 1)(line2 p33 2 kx)(line2 p32 3 1)
	(dim1 p16 p17 2 -50 "M-8")
	(if (< pg2 (- t2 350));小于说明开口只在三通上否则在双面
	(progn
	(if (= c7cd1 c7cd6)	 
		 
  (progn
	(DIM1 p46/5 p46/6 2 100 "m-8")(DIM1 p46 p46/5 1 50 "m-8")(DIM1 p46 p46/5 1 50 "m-8")(DIM1 p46/11 p22 1 -150 "m-8")(DIM1 p33 p46/6 1 100 "m-8")
)
	(progn
	(DIM1 p47 p48 2 100 "m-8")(DIM1 p46 p47 1 50 "m-8")
	(DIM1 p49 p22 2 350 "m-8")(DIM1 p29 p48 1 100 "m-8")
)))
		
		
	
  (progn

    (if (= c7cd1 c7cd6)
  (progn
	(DIM1 p18 p19b 1 50 "m-8")(DIM1 p19b p20 2 -50 "m-8")
)
  (progn
	(dim1 p19 p20 2 100 "m-8")(dim1 p18 p19 1 50 "m-8")
))
(dim1 p29 p20 1 -200 "m-8")
))
		(dim1 p17 p17/ 2 -50 "m-8")(dim1 p17/ p22 2 -50 "m-8")(dim1 p22 p23 2 -50 "m-8")(dim1 p23 p24 2 -50 "m-8")(dim1 p24 p25 1 -50 "m-15")
(dim1 p26 p27 1 150 "m-8")(dim1 p28 p29 2 100 "m-8")	(dim1 p29 p30 2 100 "m-8")	(dim1 p30 p31 2 100 "m-8")
  ;下面为变径独立部分1
	(setq p40(list (car pt0) (- (cadr pt0)2000)))
  (setq p41(list (+ (car p40) d10) (+ (cadr p40) d11)))
	(setq p42(list (car p41) (+ (cadr p41) l1)));变径独立上伸量
	(setq p43(list (+ (car p42) c7cd3) (cadr p42)))
	(setq p44(list (car p43) (cadr p41)))
	(setq p45(list (car p44) (cadr p40)))
	(MK-line (list p40 p41 p42 p43 p44 p45 ))
(line2 p41 1 1) (line2 p44 2 1)
(dim1 p41 p42 2  -50 "m-8")		(dim1 p42 p43  1  50 "m-8")(dim1 p40 p45  1  -100 "m-8")(dim1 p43 p45  2  100 "m-8")
  (setq pt8x (list(car p42) (+ (cadr p42) 800)));马口的插入起点	
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt5x(list (+ (car p22) (/ (- t2 BJ_L) 2)) (+ (cadr p22) (/ c7cd1 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt5x 200 1 1 "0")(setq xh (1+ xh))
  (setq pt6x(list (+ (car p40) (/ c7cd1 2)) (+ (cadr p40) (/ d11 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt6x 100 1 1 "0")(setq xh (1+ xh))
	)
		
	(progn
	
  (setq p16(list (+ (car p15) 1000) (cadr p15)))
  (setq p17(list (car p16) (cadr p1)))
 (if (= c7cd1 c7cd6);如果主管长等于马口宽
  (progn
  (setq p18(list (car p17) (+ (cadr p17) 0.5))
	p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9 0.2)) (cadr p18))
	p19a(list (car p19) (- (cadr p19) 0.5))
	p19b(list (+ (car p19a) 0.2) (cadr p19a))
	p20(list (car p19b) (+ (cadr p19b) c7cd6))
	p20a(list (- (CAR P20) 0.2) (cadr p20))
	p20b(list (car p20a) (- (cadr p20a) 0.5))
	p21(list (car p18) (cadr p20b))
	p22(list (car p21) (+ (cadr p21) 0.5))))
  (progn
   (setq p18(list (car p17) (+ (cadr p17) (- (/ (- c7cd1 c7cd6) 2) t1))))
   (setq p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9)) (cadr p18)))
   (setq p20(list (car p19) (+ (cadr p19) (+ c7cd6 (* t1 2)))))
   (setq p21(list (car p18) (cadr p20)))
   (setq p22(list (car p21) (+ (cadr p21) (- (/ (- c7cd1 c7cd6) 2) t1))))))
;下面为三通直管只开在支管上面的数据	   
(setq pg2(+ c7cd5 c7cd8 (* t1 2) c7cd9));开口的总长度

(if (< pg2 (- t2 BJ_L))
  (progn
	  (if (= c7cd1 c7cd6)
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p17) pg3) (cadr p17)))
		(setq p46/1(list (+ (car p46) 0.2) (cadr p17))
		      p46/2(list (car p46/1)  (+ (cadr p46/1) 0.5))
			    p46/3(list (- (+ (car p46/2) (+ c7cd5 c7cd8 (* t1 2))) 0.4)(cadr p46/2))
					p46/4(list (car p46/3) (cadr p46/1))
			    p46/5(list (+ (car p46/4) 0.2) (cadr p46/4))
			    p46/6(list (car p46/5)(+ (cadr p46/5)c7cd6 ))
			    p46/7(list (car p46/4)(cadr p46/6))
			    p46/8(list (car p46/7)(- (cadr p46/7) 0.5))
			    p46/9(list (car p46/2)(cadr p46/8))
			    p46/10(list (car p46/9)(cadr p46/7))
			    p46/11(list (- (car p46/10) 0.2)(cadr p46/10))))
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p18) pg3) (cadr p18)))
    (setq p47(list (+ (car p46) (+ c7cd5 c7cd8 (* t1 2) )) (cadr p46)))
    (setq p48(list (car p47) (+ (cadr p47) (+ c7cd6 (* t1 2)))))
    (SETQ P49(LIST (car p46) (cadr p48)))))))
    ;P46.47.48/49为开口定位点（开口只在三通面上）
  
  (setq p23(list (car p22) (+ (cadr p22) c7cd2)))
  (setq p24(list (car p23) (+ (cadr p23) c7cd1)))
  (setq p25(list (car p24) (+ (cadr p24) ts1)))
  (setq p26(list (+ (car p25) (- t2 BJ_L)) (cadr p25)))
  (setq p27(list (car p26) (cadr p24)))
  (setq p28(list (+ (car p27) d11) (- (cadr p27) d10)));标记
  (setq p29(list (+ (car p28) l1) (cadr p28)))
  (setq p30(list (car p29) (- (cadr p29) c7cd3)))
  (setq p31(list (- (car p30) l1) (cadr p30)))
  (setq p32(list (car p27) (- (cadr p27) c7cd1)))
  (setq p33(list (car p32) (- (cadr p32) c7cd2)))
  (setq p34(list (+ (car p33) (- (- BJ_L 1.5) l1)) (- (cadr p33) d10)))
  (setq p35(list (+ (car p34) l1) (cadr p34)))
  (setq p36(list (car p35) (- (cadr p35) c7cd3)))
  (setq p37(list (- (car p36) l1) (cadr p36)))
  (setq p38(list (car p33) (cadr p17)))
  (setq p39(list (car p38) (cadr p16)))
  (if (< pg2 (- t2 BJ_L))
  (progn
		(MK-line (list p16 p17 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 ))
		(if (= c7cd1 c7cd6)
			(progn
		(MK-line (list p46 p46/1 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p46/10 p46/11 )))
			(progn
		(MK-line (list p46 p47 p48 p49 )))))
		
    
  (progn
 (if (= c7cd1 c7cd6)
   
	 (MK-line (list p16 p17 p18  p19  p19a p19b p20 p20a p20b p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 ))
	 (MK-line (list p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 ))
)))
	;绘制中心线
	(entmake (list '(0 . "LINE") (cons 10 p17) (cons 11 p38) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p22) (cons 11 p33) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p23) (cons 11 p32) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p24) (cons 11 p27) (cons 62 1) (cons 8 "3中心线层")))
	(line2 p17 1 kx) (line2 p22 1 kx)(line2 p23 1 kx)(line2 p24 1 kx)(line2 p27 2 kx)(line2 p32 2 kx)(line2 p33 2 kx)(line2 p38 2 kx)
	(line2 p28 4 1) (line2 p31 3 1)(line2 p34 4 1)(line2 p37 3 1)
		

  (dim1 p16 p17 2 -30 "m-8")
   (if (< pg2 (- t2 BJ_L))
	(progn
	(if (= c7cd1 c7cd6)	 
		 
  (progn
	(dim1 p46/5 p46/6 2 130 "m-8")(dim1 p46 p46/5 1 50 "m-8")(dim1 p46/11 p22 1 -150 "m-8")(dim1 p33 p46/6 1 100 "m-8")

)
	(progn
	(dim1 p47 p48 2 130 "m-8")(dim1 p46 p47 1 50 "m-8")(dim1 (list (car p49) (cadr p22)) p49  2 -100 "m-5")(dim1 p33 p48 1 0 "m-8")	
)))
		
		
	
  (progn

    (if (= c7cd1 c7cd6)
  (progn
	(dim1 p18 p19b 1 50 "m-8")(dim1  p19b p20 2 -50 "m-8")	
)
  (progn
	(dim1 p19 p20 2 120 "m-8")(dim1 p19 (list(car p19) (cadr p17)) 2 120 "m-5")(dim1 p18 p19 1 30 "m-8")
))
(dim1 p33 p20 1 0 "m-8")
))

(dim1 p17 p22 2 -30 "m-10")(dim1 p22 p23 2 -30 "m-10")(dim1 p23 p24 2 -30 "m-10")(dim1 p24 p25 2 -30 "m-10")
(dim1 p28 p27 1 50 "m-8")	(dim1 p28 p29 1 50 "m-8")(dim1 p34 p33 1 50 "m-8")
(dim1 p29 p30 2 170 "m-10")  (dim1 p34 p35 1 50 "m-8")(dim1 p35 p36 2 170 "m-10")
(dim1 p16 p25 2 -200 "m-15") (dim1 p25 p26 1 50 "m-15")
  ;下面为变径独立部分1
  ;(setq p40(list (+ (car p36) 800) (cadr p36)))
	(setq p40(list (car pt0) (- (cadr pt0)2000)))
  (setq p41(list (+ (car p40) (- c7cd2 c7cd4)) (+ (cadr p40) d13)))
  (setq p42(list (car p41) (+ (cadr p41) l1)));变径独立上伸量
  (setq p43(list (+ (car p42) c7cd4) (cadr p42)))
  (setq p44(list (car p43) (cadr p41)))
  (setq p45(list (car p44) (cadr p40)))
	(MK-line (list p40 p41 p42 p43 p44 p45 ))
  (setq ps19(list (+ (car p41) 1) (cadr p41)));马口打点
  (setq ps20(list (- (car p44) 1) (cadr p44)))
(line2 p41 1 1)(line2 p44 2 1)
(dim1 p40 p42 2 -200 "m-8") (dim1 p44 p43 2 130 "m-8")(dim1 p44 p45 2 130 "m-8")
(dim1 p42 p43 1 50 "m-8")(dim1 p40 p45 1 -130 "m-8")
  ;下面为变径独立部分2   
  (setq pt1(list (+ (car p45) 600) (cadr p45)))
	(setq p46(list (car pt1)(cadr p44)))
	(setq p47(list (car p46)(cadr p43)))
	(setq p48(list (+(car p47)c7cd4) (cadr p47)))
	(setq p49(list(car p48)(cadr p46)))
	(setq p50(list(+(car pt1) c7cd2)(cadr pt1)))
  (MK-line (list pt1 p46 p47 p48 p49 p50))
(line2 p46 1 1)(line2 p49 2 1)
(dim1 pt1 p46 2 -50 "m-8")(dim1 p46 p47 2 -50 "m-8")(dim1 p47 p48 1 50 "m-8")(dim1 pt1 p50 1 -130 "m-8")(dim1 p48 p50 2 200 "m-8")
  (setq pt8x (list(car p42) (+ (cadr p42) 800)));马口的插入起点	
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt5x(list (+ (car p23) 382.5) (+ (cadr p22) (/ c7cd2 2))))

	(text (strcat ssd0 "/"(rtos xh)) pt5x 200 1 1 "0")(setq xh (1+ xh))
  (setq pt6x(list (+ (car p40) (/ c7cd2 2)) (+ (cadr p40) (/ d13 2))))
  (setq pt7x(list (+ (car pt1) (/ c7cd2 2)) (+ (cadr p40) (/ d13 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt6x 100 1 1 "0")(setq xh (1+ xh))
	(text (strcat ssd0 "/"(rtos xh)) pt7x 100 1 1 "0")(setq xh (1+ xh))
	))
	
	
)		
  
(defun bj2(/ p16 p17 p17/ p18 p19 p19/ p19/1 p19/2 p19/3 p19/4 p19/5 p19/6 p19/7 p19/8 p19/9 p19a p19b p20 p20a p20b p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p40 p41 p42 p43 p44 p45 p46 p46/1 p46/10 p46/11 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p47 p48 p49 pg2 pg3 ps19 ps20 pt5x pt6x pt8x)


	(if (= ssd1 ssd3)
	(progn
		(setq p16(list (+ (car p15) 1000) (cadr p15)))
		(setq p17(list (car p16) (+ (cadr p16)(- c7cd1 ts1)))
			    p17/(list (car p17)(+ (cadr p17) c7cd2)))
		(if (= c7cd1 c7cd6);如果主管长等于马口宽
    (progn
			(setq p18(list (car p17/) (+ (cadr p17/) 0.5))
				p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9 0.2)) (cadr p18))
				p19a(list (car p19) (- (cadr p19) 0.5))
				p19b(list (+ (car p19a) 0.2) (cadr p19a))
				p20(list (car p19b) (+ (cadr p19b) c7cd6))
				p20a(list (- (CAR P20) 0.2) (cadr p20))
				p20b(list (car p20a) (- (cadr p20a) 0.5))
				p21(list (car p18) (cadr p20b))
				p22(list (car p21) (+ (cadr p21) 0.5))))
  (progn
   (setq p18(list (car p17/) (+ (cadr p17/) (- (/ (- c7cd1 c7cd6) 2) t1))))
   (setq p19(list (+ (car p18) (- (- t2 BJ_L) c7cd9)) (cadr p18)))
   (setq p20(list (car p19) (+ (cadr p19) (+ c7cd6 (* t1 2)))))
   (setq p21(list (car p18) (cadr p20)))
   (setq p22(list (car p21) (+ (cadr p21) (- (/ (- c7cd1 c7cd6) 2) t1))))))	
	;下面为三通直管只开在支管上面的数据	   
  (setq pg2(+ c7cd5 c7cd8 (* t1 2) c7cd9));开口的总长度
	(if (< pg2 (- t2 BJ_L))
  (progn
	  (if (= c7cd1 c7cd6)
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p17/) pg3) (cadr p17/)))
		(setq p46/1(list (+ (car p46) 0.2) (cadr p17/))
		      p46/2(list (car p46/1)  (+ (cadr p46/1) 0.5))
			    p46/3(list (- (+ (car p46/2) (+ c7cd5 c7cd8 (* t1 2))) 0.4)(cadr p46/2))
					p46/4(list (car p46/3) (cadr p46/1))
			    p46/5(list (+ (car p46/4) 0.2) (cadr p46/4))
			    p46/6(list (car p46/5)(+ (cadr p46/5)c7cd6 ))
			    p46/7(list (car p46/4)(cadr p46/6))
			    p46/8(list (car p46/7)(- (cadr p46/7) 0.5))
			    p46/9(list (car p46/2)(cadr p46/8))
			    p46/10(list (car p46/9)(cadr p46/7))
			    p46/11(list (- (car p46/10) 0.2)(cadr p46/10))))
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p18) pg3) (cadr p18)))
    (setq p47(list (+ (car p46) (+ c7cd5 c7cd8 (* t1 2) )) (cadr p46)))
    (setq p48(list (car p47) (+ (cadr p47) (+ c7cd6 (* t1 2)))))
    (SETQ P49(LIST (car p46) (cadr p48)))))))
    ;P46.47.48/49为开口定位点（开口只在三通面上）
   (setq p23(list (car p22) (+ (cadr p22) c7cd2)))
   (setq p24(list (car p23) (+ (cadr p23) ts1)))
  ;(setq p25(list (car p24) (+ (cadr p24) 148.5)))
   (setq p25(list (+ (car p24) (- t2 BJ_L)) (cadr p24)))
   (setq p26(list (car p25) (cadr p23)));这个要与p23作为第一个打标点，和中心线的连接点
		;(setq p41(list (+ (car p40) (- c7cd2 c7cd4)) (+ (cadr p40) d13)))
	  ;下面为变径部分
   (setq p27(list (+ (car p26) d13) (- (cadr p26) (- c7cd2 c7cd4))));标记,变径打标点
	 (setq p28(list (+ (car p27) l1) (cadr p27)))
   (setq p29(list (car p28) (- (cadr p28) c7cd4)));第二个打标点，这个点的位置与p22连接作为第二个打标点
	 (setq p30(list (car p29) (- (cadr p29)c7cd3)));第三个打标点
   (setq p31(list (car p30) (-(cadr p30)c7cd4)));第四个个打标点
	 (setq p32(list (car p27)(cadr p31)))
	 (setq p33(list (car p25)(cadr p17)))
	 (setq p34(list (car p33)(cadr p16)))
  (if (< pg2 (- t2 BJ_L))
  (progn
		(MK-line (list p16 p17 p17/ p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34  ))
		(if (= c7cd1 c7cd6)
			(progn
		(MK-line (list p46 p46/1 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p46/10 p46/11 )))
			(progn
		(MK-line (list p46 p47 p48 p49 )))))
		
    
  (progn
 (if (= c7cd1 c7cd6)
   
	 (MK-line (list p16 p17 p17/ p18  p19  p19a p19b p20 p20a p20b p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 ))
	 (MK-line (list p16 p17 p17/ p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34  ))
)))

	;		;绘制中心线
	(entmake (list '(0 . "LINE") (cons 10 p17) (cons 11 p33) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p17/) (cons 11 p30) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p22) (cons 11 p29) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p23) (cons 11 p26) (cons 62 1) (cons 8 "3中心线层")))
  (line2 p17 1 kx)(line2 p21 1 kx)(line2 p22 1 kx) (line2 p23 1 kx) (line2 p26 2 kx)(line2 p29 2 kx)(line2 p30 2 kx)
  (line2 p27 4 1)(line2 p33 2 kx)(line2 p32 3 1)
	(dim1 p16 p17 2 -50 "M-8")
	(if (< pg2 (- t2 350));小于说明开口只在三通上否则在双面
	(progn
	(if (= c7cd1 c7cd6)	 
		 
  (progn
	(DIM1 p46/5 p46/6 2 100 "m-8")(DIM1 p46 p46/5 1 50 "m-8")(DIM1 p46 p46/5 1 50 "m-8")(DIM1 p46/11 p22 1 -150 "m-8")(DIM1 p33 p46/6 1 100 "m-8")
)
	(progn
	(DIM1 p47 p48 2 100 "m-8")(DIM1 p46 p47 1 50 "m-8")
	(DIM1 p49 p22 2 350 "m-8")(DIM1 p29 p48 1 100 "m-8")
)))
		
		
	
  (progn

    (if (= c7cd1 c7cd6)
  (progn
	(DIM1 p18 p19b 1 50 "m-8")(DIM1 p19b p20 2 -50 "m-8")
)
  (progn
	(dim1 p19 p20 2 100 "m-8")(dim1 p18 p19 1 50 "m-8")
))
(dim1 p29 p20 1 -200 "m-8")
))
		(dim1 p17 p17/ 2 -50 "m-8")(dim1 p17/ p22 2 -50 "m-8")(dim1 p22 p23 2 -50 "m-8")(dim1 p23 p24 2 -50 "m-8")(dim1 p24 p25 1 -50 "m-15")
(dim1 p26 p27 1 150 "m-8")(dim1 p28 p29 2 100 "m-8")	(dim1 p29 p30 2 100 "m-8")	(dim1 p30 p31 2 100 "m-8")
  ;下面为变径独立部分1
	(setq p40(list (car pt0) (- (cadr pt0)2000)))
  (setq p41(list (+ (car p40) d10) (+ (cadr p40) d11)))
	(setq p42(list (car p41) (+ (cadr p41) l1)));变径独立上伸量
	(setq p43(list (+ (car p42) c7cd3) (cadr p42)))
	(setq p44(list (car p43) (cadr p41)))
	(setq p45(list (car p44) (cadr p40)))
	(MK-line (list p40 p41 p42 p43 p44 p45 ))
(line2 p41 1 1) (line2 p44 2 1)
(dim1 p41 p42 2  -50 "m-8")		(dim1 p42 p43  1  50 "m-8")(dim1 p40 p45  1  -100 "m-8")(dim1 p43 p45  2  100 "m-8")
  (setq pt8x (list(car p42) (+ (cadr p42) 800)));马口的插入起点	
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt5x(list (+ (car p22) (/ (- t2 BJ_L) 2)) (+ (cadr p22) (/ c7cd1 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt5x 200 1 1 "0")(setq xh (1+ xh))
  (setq pt6x(list (+ (car p40) (/ c7cd1 2)) (+ (cadr p40) (/ d11 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt6x 100 1 1 "0")(setq xh (1+ xh))
	)
	
	(progn	
	
  (setq p16(aa p15 1000 0);三通起始点
		    p17(aa p16 0 (- c7cd2 ts1 50));多减50避焊缝，H2
		    p18(AA P17 0 c7cd1);H3
		    p19(aa p18 0 c7cd2);H4
		    p19/(AA P19 0 (- (/ (- c7cd1 c7cd6) 2) t1))			
	      P20(AA P19 0 C7CD1);H5 
	      P21(AA P20 0 (+ TS1 50));H6，三通H方向最高点
		    p22(AA P21 (- t2 BJ_L) 0 )
		    P23(AB P22 P20 0 0)
		    p24(AA P23 (- (- BJ_L 1.5) l1)  (* d14 -1));侧平变径第一点
		    p25(AA P24  L1 0)
		    P26(AB p25 p19 0 0)
		    p27(aa p26  0  (* c7cd4 -1))
		    p28(AA P27 (* l1 -1) 0 )			   
		    p29(AB P22 P18 0 0)
		    P30(AA P29 d11 0)
		    p31(aa p30 L1 0 )
		    p32(aa p31 0 (* c7cd3 -1 ))
		    p33(aa p32 (* l1 -1) 0 )
		    p34(ab p22 p17 0 0)
		    p35(AB P22 P16 0 0))
(if (= c7cd1 c7cd6);如果主管长等于马口宽
  (progn
  (setq p19/1(list (car p19) (+ (cadr p19) 0.5))
	p19/2(list (+ (car p19/1) (- (- t2 BJ_L) c7cd9 0.2)) (cadr p19/1))
	p19/3(list (car p19/2) (- (cadr p19/2) 0.5))
	p19/4(list (+ (car p19/3) 0.2) (cadr p19/3))
	p19/5(list (car p19/4) (+ (cadr p19/4) c7cd6))
	p19/6(list (- (CAR P19/5) 0.2) (cadr p19/5))
	p19/7(list (car p19/6) (- (cadr p19/6) 0.5))
	p19/8(list (car p19/1) (cadr p19/7))
	p19/9(list (car p19/8) (+ (cadr p19/8) 0.5))))
  (progn
   (setq p19/1(list (car p19) (+ (cadr p19) (- (/ (- c7cd1 c7cd6) 2) t1))))
   (setq p19/2(list (+ (car p19/1) (- (- t2 BJ_L) c7cd9)) (cadr p19/1)))
   (setq p19/3(list (car p19/2) (+ (cadr p19/2) (+ c7cd6 (* t1 2)))))
   (setq p19/4(list (car p19/1) (cadr p19/3)))
   ))
	;(setq p19/5(list (car p19/4) (+ (cadr p19/4) (- (/ (- c7cd1 c7cd6) 2) t1))))	    
;下面为三通直管只开在支管上面的数据				
(setq pg2(+ c7cd5 c7cd8 (* t1 2) c7cd9));开口的总长度		
(if (< pg2 (- t2 BJ_L))
  (progn
	  (if (= c7cd1 c7cd6)
			(progn
    (setq pg3(- (- t2 BJ_L) pg2));三通直管总长减去开口长度
    (setq p46(list (+ (car p19) pg3) (cadr p19)))
		(setq p46/1(list (+ (car p46) 0.2) (cadr p19))
		      p46/2(list (car p46/1)  (+ (cadr p46/1) 0.5))
			    p46/3(list (- (+ (car p46/2) (+ c7cd5 c7cd8 (* t1 2))) 0.4)(cadr p46/2))
					p46/4(list (car p46/3) (cadr p46/1))
			    p46/5(list (+ (car p46/4) 0.2) (cadr p46/4))
			    p46/6(list (car p46/5)(+ (cadr p46/5)c7cd6 ))
			    p46/7(list (car p46/4)(cadr p46/6))
			    p46/8(list (car p46/7)(- (cadr p46/7) 0.5))
			    p46/9(list (car p46/2)(cadr p46/8))
			    p46/10(list (car p46/9)(cadr p46/7))
			    p46/11(list (- (car p46/10) 0.2)(cadr p46/10))))
			(progn
				(setq pg3(- (- t2 BJ_L) pg2);三通直管总长减去开口长度
					p46(list (+ (car p19/) pg3) (cadr p19/))
					p47(list (+ (car p46) (+ c7cd5 c7cd8 (* t1 2) )) (cadr p46))
					p48(list (car p47) (+ (cadr p47) (+ c7cd6 (* t1 2))))
					P49(LIST (car p46) (cadr p48)))
			))))
    ;P46.47.48/49为开口定位点（开口只在三通面上）
	(if (< pg2 (- t2 BJ_L))
  (progn
		(MK-line (list p16 p17 P18 P19 P20 P21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35  ))
		(if (= c7cd1 c7cd6)
			(progn
		(MK-line (list p46 p46/1 p46/2 p46/3 p46/4 p46/5 p46/6 p46/7 p46/8 p46/9 p46/10 p46/11 )))
			(progn
		(MK-line (list p46 p47 p48 p49 )))))
		
    
  (progn
 (if (= c7cd1 c7cd6)
   
	 (MK-line (list p16 p17 p18  p19  p19/1 p19/2 p19/3 p19/4 p19/5 p19/6 p19/7 p19/8 p19/9  p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 ))
	 (MK-line (list p16 p17 p18 p19  p19/1 p19/2 p19/3 p19/4  p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)))	
		
	;绘制中心线
	(entmake (list '(0 . "LINE") (cons 10 p17) (cons 11 p34) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p18) (cons 11 p29) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p19) (cons 11 p26) (cons 62 1) (cons 8 "3中心线层")))
	(entmake (list '(0 . "LINE") (cons 10 p20) (cons 11 p23) (cons 62 1) (cons 8 "3中心线层")))
	(line2 p17 1 kx) (line2 p18 1 kx)(line2 p19 1 kx)(line2 p20 1 kx)(line2 p23 2 kx)(line2 p26 2 kx)(line2 p29 2 kx)(line2 p34 2 kx)
	(line2 p24 4 1) (line2 p28 3 1)(line2 p30 4 1)(line2 p33 3 1)
		
;;;;;;;;;;;;;;;;;;;;;;;;
  (dim1 p16 p17 2 -30 "m-8")
   (if (< pg2 (- t2 BJ_L))
	(progn
	(if (= c7cd1 c7cd6)	 
		 
  (progn
	(dim1 p46/5 p46/6 2 130 "m-8")(dim1 p46 p46/5 1 50 "m-8")(dim1 p46/11 p20 1 -150 "m-8")(dim1 p23 p46/6 1 100 "m-8")

)
	(progn
	(dim1 p47 p48 2 130 "m-8")(dim1 p46 p47 1 50 "m-8")(dim1 (list (car p49) (cadr p20)) p49  2 -100 "m-5")(dim1 p23 p48 1 0 "m-8")	
)))
		
		
	
  (progn

    (if (= c7cd1 c7cd6)
  (progn
	(dim1 p19/1 p19/4 1 50 "m-8")(dim1  p19/4 p19/5 2 -50 "m-8")	
)
  (progn
	(dim1 p19/1 p19/2 1 120 "m-8")(dim1 p19/1 (list(car p19/1) (cadr p19)) 2 120 "m-5")(dim1 p19/2 p19/3 2 150 "m-8")
))
(dim1 p23 p19/3 1 -150 "m-8")
))

(dim1 p17 p18 2 -30 "m-10")(dim1 p18 p19 2 -30 "m-10")(dim1 p19 p20 2 -30 "m-10")(dim1 p20 p21 2 -30 "m-10")
(dim1 p23 p24 1 50 "m-8")	(dim1 p24 p25 1 50 "m-8")(dim1 p34 p33 1 50 "m-8")(dim1 p33 p32 1 -50 "m-8")(dim1 p28 p29 2 -50 "m-8")
(dim1 p25 p26 2 170 "m-10")(dim1 p31 p32 2 170 "m-10")(dim1 p26 p27 2 170 "m-10")
(dim1 p16 p21 2 -200 "m-15") (dim1 p21 p22 1 50 "m-15")
  ;下面为变径独立部分1
	(setq p40(list (car pt0) (- (cadr pt0)2000)))
  (setq p41(list (+ (car p40) (- c7cd2 c7cd4)) (+ (cadr p40) d16)))
  (setq p42(list (car p41) (+ (cadr p41) l1)));变径独立上伸量
  (setq p43(list (+ (car p42) c7cd4) (cadr p42)))
  (setq p44(list (car p43) (cadr p41)))
  (setq p45(list (car p44) (cadr p40)))
	(MK-line (list p40 p41 p42 p43 p44 p45 ))
  (setq ps19(list (+ (car p41) 1) (cadr p41)));马口打点
  (setq ps20(list (- (car p44) 1) (cadr p44)))
(line2 p41 1 1)(line2 p44 2 1)
(dim1 p40 p42 2 -200 "m-8") (dim1 p44 p43 2 130 "m-8")(dim1 p44 p45 2 130 "m-8")
(dim1 p42 p43 1 50 "m-8")(dim1 p40 p45 1 -130 "m-8")
 
  (setq pt8x (list(car p42) (+ (cadr p42) 800)));马口的插入起点	
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt5x(list (+ (car p18) 382.5) (+ (cadr p18) (/ c7cd2 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt5x 200 1 1 "0")(setq xh (1+ xh))
  (setq pt6x(list (+ (car p40) (/ c7cd2 2)) (+ (cadr p40) (/ d13 2))))
  ;(setq pt7x(list (+ (car pt1) (/ c7cd2 2)) (+ (cadr p40) (/ d13 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt6x 100 1 1 "0")(setq xh (1+ xh))
	;(text (strcat xh "/6") pt7x 100 1 1 "0")
	))

	
)		
		
	(cond ((= ssd11 0)
		(bj1))
		((= ssd11 1)
		(bj2))
		)		
)

		
		
  ;下面程序为只有三通，没有直管的定义
  (progn
	(defun zhu2 (/ b1 b2 b3 b4 b5 b6 b7 b8 b9 c7cd10 jx-1 jx-2 p1 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p2 p20 p21 p22 p3 p4 p5 p6 p7 p8 p9 pg2 pg3 pt1 pt2 pt3 pt5x pt6x pt7x pt8x)
(setq c7cd10(- ssd10 t1 BJ_L));C7CD10为直段长度
(setq pg2(+ c7cd5 c7cd8 (* t1 2) c7cd9));开口的总长度
(setq pg3(- c7cd10 pg2))

;上面为需要的参数,下面开始绘制矩形的基础数据
(setq	p1(list (car pt0) (+ (cadr pt0) (- c7cd2 ts1)))
			p2(list (car p1) (+ (cadr p1) c7cd1))
			p3(list (car p2) (+ (cadr p2) c7cd2))
			p4(list (car p3) (+ (cadr p3) c7cd1))
			p5(list (car p4) (+ (cadr p4) ts1));顶
			p6(list (+ (car p5) c7cd10) (cadr p5))
			p7(list (car p6) (- (cadr p6) ts1))
	    P8(AB P7 P3 0 0)
	    P9(AB P8 P2 0 0)
		  P10(AB P9 P1 0 0)
	    P11(AB P10 PT0 0 0))
(MK-line3 (list p1 p10) 1 "3中心线层") (MK-line3 (list p2 p9) 1 "3中心线层")
(MK-line3 (list p4 p7) 1 "3中心线层")
(dim1 pt0 p1 2 -30 "m-10")(dim1 p1 p2 2 -30 "m-10")(dim1 p2 p3 2 -30 "m-10")(dim1 p3 p4 2 -30 "m-10")	(dim1 p4 p5 2 -30 "m-10")
(dim1 pt0 p5 2 -200 "m-15")	(dim1 p5 p6 1 30 "m-15") 
(line2 p1 1 kx)(line2 p2 1 kx)(line2 p3 1 kx)(line2 p4 1 kx)
(line2 p7 2 kx)(line2 p9 2 kx)(line2 p10 2 kx)
	
(defun jx-1 (pt0 W H / p1 p10 p11 p2 p3 p4 p5  p7 p8 p9)
(setq p1 (AA pt0 0.2 0)
	    p2 (AA P1 0 0.5)
	    P3 (aa p2 (- w 0.4) 0)
	    p4 (aa p3 0 -0.5)
	    p5 (aa p4 0.2 0)
	    px (aa p5 0 h)
	    p7(aa px -0.2 0)
	    p8(aa p7 0 -0.5)
	    p9(ab p2 p8 0 0 )
	    p10(aa p9 0 0.5)
	    p11(aa p10 -0.2 0))
(MK-line (list pt0 p1 p2 p3 p4 p5 px p7 p8 p9 p10 p11))				 
(dim1 pt0 p5 1 50 "m-8")	(dim1 p5 px 2 -50 "m-8")				 	
)	
		
(defun jx-2 (pt0 W H / )
(setq px (AA pt0 w 0)
	    py (AA Px 0 h)
	    Pz (ab pt0 py 0 0)
)
(MK-line (list pt0 px py pz ))				 
(dim1 pt0 px 1 50 "m-8")	(dim1 px py 2 -50 "m-8")				 	
)		
	
;底平中变变径三通
(cond 
((= ssd11 0)
	(setq B1(AA P7 d11 (* D10  -1 ))
		b2(AA B1 l1 0)	
		b3(AA B2 0 (* -1 c7cd3))
		b4(AA b3 (* -1 l1) 0 )
		;上面为带出变径的第一部分
		b5(aa p9 (- (- BJ_L 1.5) l1) (* -1 d10))
		B6(aa B5 L1 0)
		B7(aa b6 0 (* -1 c7cd3))
		b8(aa b7 (* -1 l1) 0))
(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 b1 b2 b3 b4 p8 p9 b5 b6 b7 b8 p10 p11))
(dim1 p7 b1 1 30 "m-8")(dim1 b1 b2 1 30 "m-8")(dim1 b2 b3 2 170 "m-10")	(dim1 b3 p8 2 0 "m-8")
(dim1 p9 b6 1 50 "m-8")(dim1 b6 b7 2 170 "m-8")
(line1 b1 4 )(line1 b4 3 )(line1 b5 4 )(line1 b8 3 )(line2 p8 2 kx )
(MK-line3 (list p3 p8) 1 "3中心线层")
;开始绘制开口矩形
(if (= c7cd2 c7cd6)
(progn 
	(jx-1 (list (+ (car p1)  pg3) (cadr p1)) (+ ssd5 ssd8) c7cd6 )
	(dim1 p9 px  1 50 "m-8")
)
(progn
 (jx-2 (list (+ (car p1)  pg3) (+ (cadr p1) (/ (- c7cd1 ssd6) 2))) (+ ssd5 ssd8) ssd6)	
(dim1 p9 py  1 50 "m-8")(dim1 px (list (car px) (cadr p10)) 2 -50 "m-8")	
))
				
(setq xh 0)				
(if (<= FL (- (car b2) (car p4)));当需要分料的情况时S
			(progn
				(setq pt1 (AA P5 0 (* FL -1)))
				(if (< (cadr pt1) (cadr p2)) 
				(progn	
				(setq pt1 (h-mid p3 p2))
				(MK-line1 (list pt1 (list (car p8) (cadr pt1))))
        (dim1 p6 (list (car p8) (cadr pt1)) 2 1000 "m-15")
        (dim1 (list (car p8) (cadr pt1)) p11  2 1000 "m-15")
       	(text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 p5))) 200 1 1 "0")
				(setq xh (1+ xh))
		    (text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 pt0))) 200 1 1 "0")	
			  (setq xh (1+ xh))		
				)
				(progn					
				(MK-line1 (list pt1 (list (car p8) (cadr pt1))))
				(dim1 p6 (list (car p8) (cadr pt1)) 2 1000 "m-15")
        (setq pt2 (list (car pt1) (- (cadr pt1) FL)))
				(text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 p5))) 200 1 1 "0")
				(setq xh (1+ xh))
        (if (and (> (cadr pt2) (cadr p1)) (< (cadr pt2) (cadr p2)))
        (progn	
				(setq pt2 (list(car p2) (+ (cadr p2) 100)))
				(dim1 (list (car p8) (cadr pt1))  (list (car p8) (cadr pt2)) 2 1000 "m-15")
				(MK-line1 (list pt2 (list (car p8) (cadr pt2))))
				(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt1))) 200 1 1 "0")
				(setq xh (1+ xh))
				(setq pt3 (list(car p2) (- (cadr pt2) FL)))	
					(if (> (cadr pt3) (cadr pt0))
						(progn
							(MK-line1 (list pt3 (list (car p8) (cadr pt3))))
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt3))) 200 1 1 "0")
							(setq xh (1+ xh))
							(text (strcat ssd0 "/4") (list (car (h-mid p5 p6)) (cadr (h-mid pt3 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  (list (car p8) (cadr pt3)) 2 1000 "m-15")
							(dim1 (list (car p8) (cadr pt3))  p11 2 1000 "m-10")
						)
						(progn
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  p11  2 1000 "m-10")	
						)))
				(progn
					(setq pt2 (AA pt1 0 (* FL -1)))
				(if (> (cadr pt2) (cadr pt0))
						(progn
							(MK-line1 (list pt2 (list (car p8) (cadr pt2))))
							(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 pt2))) 200 1 1 "0")
							(setq xh (1+ xh))
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt1))  (list (car p8) (cadr pt2)) 2 1000 "m-15")
							(dim1 (list (car p8) (cadr pt2))  p11 2 1000 "m-10")
						)
						(progn
							(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  p11  2 1000 "m-10")	
						)))
				)
					
				
				)	
				 ))
	    (progn
	    (text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid p2 p3))) 200 1 1 "0")
	    (setq xh (1+ xh)))
			)
;下面为变径独立部分1
	(setq p12(list (car pt0) (- (cadr pt0)2000)))
  (setq p13(list (+ (car p12) (- c7cd2 c7cd4)) (+ (cadr p12) d13)))
  (setq p14(list (car p13) (+ (cadr p13) l1)));变径独立上伸量
  (setq p15(list (+ (car p14) c7cd4) (cadr p14)))
  (setq p16(list (car p15) (cadr p13)))
  (setq p17(list (car p16) (cadr p12)))
	(MK-line (list p12 p13 p14 p15 p16 p17 ))
	(line2 p13 1 1)(line2 p16 2 1)
(dim1 p12 p14 2 -50 "m-8")(dim1 p14 p15 1 30 "m-8")(dim1 p12 p17 1 -120 "m-8")(dim1 p16 p15 2 120 "m-8")(dim1 p16 p17 2 120 "m-8") 
  ;下面为变径独立部分2
	
  (setq pt1(list (+ (car p17) 600) (cadr p17)))
	(setq p18(list (car pt1)(cadr p16)))
	(setq p19(list (car p18)(cadr p15)))
	(setq p20(list (+(car p19)c7cd4) (cadr p19)))
	(setq p21(list(car p20)(cadr p18)))
	(setq p22(list(+(car pt1) c7cd2)(cadr pt1)))
  (MK-line (list pt1 p18 p19 p20 p21 p22))
	(line2 p18 1 1)(line2 p21 2 1)
(dim1 pt1 p18 2 -50"m-8")(dim1 p18 p19 2 -50 "m-8")(dim1 p19 p20 1 50 "m-8")(dim1 p22 p20 2 120 "m-8")(dim1 pt1 p22 1 -120 "m-8")
	(setq xh (1+ xh))
  (setq pt8x (list(car p14) (+ (cadr p14) 800)));马口的插入起点	
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt6x(list (+ (car p12) (/ c7cd2 2)) (+ (cadr p12) (/ d13 2))))
  (setq pt7x(list (+ (car pt1) (/ c7cd2 2)) (+ (cadr p22) (/ d13 2))))
	(text (strcat ssd0 "/"(rtos xh)) pt6x 150 1 1 "0")
	(setq xh (1+ xh))
	(text (strcat ssd0 "/"(rtos xh)) pt7x 150 1 1 "0")	
		)				
			
;底平侧平变径三通	
((= ssd11 1)
	(setq b1 (AA P7 (- (- BJ_L 1.5) l1)  (* d14 -1));侧平变径第一点
	      b2 (AA b1  L1 0)	
		    b3 (AB B2 p3 0 0)
		    B4 (AA B3 0  (* c7cd4 -1))
		    B5 (aa b4 (* l1 -1) 0)
		    b6 (aa p9 d11 0)
		    b7 (aa b6 L1 0)
		    b8 (aa b7 0 (* c7cd3 -1 ))
		    b9 (aa b8  (* l1 -1) 0))
(MK-line3 (list p3 b3) 1 "3中心线层")	
(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 b1 b2 b3 b4 b5 p9 b6 b7 b8 b9 p10 p11))		    
(line1 b1 4)(line2 b3 2 kx)(line1 b5 3)		(line1 b6 4)(line1 b9 3)
(dim1 p7 b1 1 30 "m-8")(dim1 b1 b2 1 30 "m-8")(dim1 b2 b3 2 170 "m-10")(dim1 b3 b4 2 170 "m-10")	(dim1 p9 b4  1 50 "m-8") (dim1 b7 b8 2 170 "m-10")
(dim1 b9 b8 1 -100 "m-8")(dim1 b9 p10 1 -170 "m-8")		
(if (= c7cd2 c7cd6)
(progn 
	(jx-1 (list (+ (car p3)  pg3) (cadr p3)) (+ ssd5 ssd8) c7cd6 )
	(dim1 p7 px  1 50 "m-8")
)
(progn
 (jx-2 (list (+ (car p3)  pg3) (+ (cadr p3) (/ (- c7cd2 ssd6) 2))) (+ ssd5 ssd8) ssd6)	
(dim1 p7 py  1 50 "m-8")(dim1 px (list (car px) (cadr p8)) 2 -50 "m-8")	
))
(setq xh 0)
(if (<= FL (- (car b2) (car p4)));当需要分料的情况时S
			(progn
				(setq pt1 (AA P5 0 (* FL -1)))
				(if (< (cadr pt1) (cadr p2)) 
				(progn	
				(setq pt1 (h-mid p3 p2))
				(MK-line1 (list pt1 (list (car p8) (cadr pt1))))
        (dim1 p6 (list (car p8) (cadr pt1)) 2 1000 "m-15")
        (dim1 (list (car p8) (cadr pt1)) p11  2 1000 "m-15")
       	(text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 p5))) 200 1 1 "0")
				(setq xh (1+ xh))
		    (text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 pt0))) 200 1 1 "0")	
			  (setq xh (1+ xh))		
				)
				(progn					
				(MK-line1 (list pt1 (list (car p8) (cadr pt1))))
				(dim1 p6 (list (car p8) (cadr pt1)) 2 1000 "m-15")
        (setq pt2 (list (car pt1) (- (cadr pt1) FL)))
				(text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 p5))) 200 1 1 "0")
				(setq xh (1+ xh))
        (if (and (> (cadr pt2) (cadr p1)) (< (cadr pt2) (cadr p2)))
        (progn	
				(setq pt2 (list(car p2) (+ (cadr p2) 100)))
				(dim1 (list (car p8) (cadr pt1))  (list (car p8) (cadr pt2)) 2 1000 "m-15")
				(MK-line1 (list pt2 (list (car p8) (cadr pt2))))
				(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt1))) 200 1 1 "0")
				(setq xh (1+ xh))
				(setq pt3 (list(car p2) (- (cadr pt2) FL)))	
					(if (> (cadr pt3) (cadr pt0))
						(progn
							(MK-line1 (list pt3 (list (car p8) (cadr pt3))))
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt3))) 200 1 1 "0")
							(setq xh (1+ xh))
							(text (strcat ssd0 "/4") (list (car (h-mid p5 p6)) (cadr (h-mid pt3 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  (list (car p8) (cadr pt3)) 2 1000 "m-15")
							(dim1 (list (car p8) (cadr pt3))  p11 2 1000 "m-10")
						)
						(progn
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  p11  2 1000 "m-10")	
						)))
				(progn
					(setq pt2 (AA pt1 0 (* FL -1)))
				(if (> (cadr pt2) (cadr pt0))
						(progn
							(MK-line1 (list pt2 (list (car p8) (cadr pt2))))
							(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt1 pt2))) 200 1 1 "0")
							(setq xh (1+ xh))
							(text (strcat ssd0 "/3") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt1))  (list (car p8) (cadr pt2)) 2 1000 "m-15")
							(dim1 (list (car p8) (cadr pt2))  p11 2 1000 "m-10")
						)
						(progn
							(text (strcat ssd0 "/2") (list (car (h-mid p5 p6)) (cadr (h-mid pt2 pt0))) 200 1 1 "0")
							(setq xh (1+ xh))
							(dim1 (list (car p8) (cadr pt2))  p11  2 1000 "m-10")	
						)))
				)
					
				
				)	
				 ))
	    (progn
	    (text (strcat ssd0 "/1") (list (car (h-mid p5 p6)) (cadr (h-mid p2 p3))) 200 1 1 "0")
	    (setq xh (1+ xh)))
			)	
	
  (setq p12(list (car pt0) (- (cadr pt0)2000)))
  (setq p13(list (+ (car p12) d10) (+ (cadr p12) d11)))
	(setq p14(list (car p13) (+ (cadr p13) l1)));变径独立上伸量
	(setq p15(list (+ (car p14) c7cd3) (cadr p14)))
	(setq p16(list (car p15) (cadr p13)))
	(setq p17(list (car p16) (cadr p12)))
	(MK-line (list p12 p13 p14 p15 p16 p17 ))
(line2 p13 1 1) (line2 p16 2 1)
(dim1 p13 p14 2  -50 "m-8")		(dim1 p14 p15  1  50 "m-8")(dim1 p12 p17  1  -100 "m-8")(dim1 p15 p17  2  100 "m-8")
  (setq pt8x (list(car p14) (+ (cadr p14) 800)));马口的插入起点	
	(setq xh (1+ xh))
  (c6r pt8x ssd5 ssd6 ssd8 c7cd7  48.5 t1)
  (setq pt5x(list (car (h-mid p14 p15)) (cadr (h-mid p14 p12))))
	(text (strcat ssd0 "/"(rtos xh)) pt5x 200 1 1 "0")
	(setq xh (1+ xh))
	
	))	
		)		
	(zhu2)	
	));该制图为小于3900出图
		(setvar "osmode" 16383)  ;打开对象捕捉状态
   
  (command "._undo" "_end")
	(princ);静默退出
  )
	(defun test1 (/ *excel* *sheet* *xlapp*  exname pcs pcs1 pt0)
  (vl-load-com)
(defun get-desktop-path ()
  (strcat (getenv "USERPROFILE") "\\Desktop\\")
)

  ;(setq exname "C:\\Users\\Administrator\\Desktop\\自动生成参数1.xlsx")
	(setq exname "D:\\小辉插件\\标准模板\\自动化生成数据表.xls")
	;(setq exname "Z:\\自动生成参数1.xls")	
  (setq *excel* (vlax-create-object "excel.application"))
  (setq *xlapp* (vlax-invoke-method (vlax-get-property *excel* 'Workbooks) 'Open exname))
  (vla-put-visible *excel* 0)  ;;显示工作表
  (setq *sheet* (vlax-get-property (vlax-get-property *xlapp* 'Worksheets) 'item "底平中变变径三通"))
	(setq pcs (atof(Ljx-read-excel-text1 "N" 2 *sheet*)))
	(setq pt0(getpoint "请输入插入的位置："))	
	(SETQ pcs1 1)(SETQ n1 1)
	    (while	
			
				(> pcs 0)
				(progn
				(setq pcs(- pcs 1))
				(SETQ pcs1(+ pcs1 1))
					(setq n1 (+ n1 1))
		(if 
			(<= n1 6)
		(setq pt0 (list (+ (car pt0) 8000) (cadr pt0)))
		)
		(if (> n1 6)
			(progn
			(setq pt0 (list (- (car pt0) (* 5 8000)) (- (cadr pt0) 20000)))
			 (setq n1 1)))
		
					
				
			
				
			(setq	ssd0 (itoa(atoi(Ljx-read-excel-text1  "B" PCS1 *sheet*)))
				    ssd1 (atof(Ljx-read-excel-text1  "C" PCS1 *sheet*))
				    ssd2 (atof(Ljx-read-excel-text1  "D" PCS1 *sheet*))
				    ssd3 (atof(Ljx-read-excel-text1  "E" PCS1 *sheet*))
			    	ssd4 (atof(Ljx-read-excel-text1  "F" PCS1 *sheet*))
				    ssd5 (atof(Ljx-read-excel-text1  "G" PCS1 *sheet*))
			      ssd6 (atof(Ljx-read-excel-text1  "H" PCS1 *sheet*))
		        ssd7 (atof(Ljx-read-excel-text1  "I" PCS1 *sheet*))
		        ssd8 (atof(Ljx-read-excel-text1  "J" PCS1 *sheet*))
		        ssd9 (atof(Ljx-read-excel-text1  "K" PCS1 *sheet*))
			      ssd10 (atof(Ljx-read-excel-text1  "L" PCS1 *sheet*))		
				)
				(c7R pt0)	
			))   
  (vlax-invoke-method (vlax-get-property *excel* "ActiveWorkbook") 'Close 0)
  (vlax-invoke-method *excel* 'QUIT)
  (vlax-release-object *sheet*) 
  (vlax-release-object *xlapp*)
	 	
)
	(defun Ljx-read-excel-data1 (vv hor sh) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2))
)


(defun Ljx-read-excel-text1 (vv hor sh /  ru) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vl-princ-to-string (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2)))
);;;;;读取数excel数据函数输出text格式
(defun ljx-vlxls-get-range-value1 ( sheet rangeid / range value valuelist )
  (setq range (vlax-get-property sheet 'Range rangeid))
  (setq value (vlax-get-property range 'Value2))
  (cond
    ((= (vlax-variant-type value)  8204);;;为数组时，即为区域;
        (progn
          (setq value (vlax-safearray->list(vlax-variant-value value)))
          (setq valuelist (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) value))
        )
    )
    ( T;;;;为单个单元格;
      (setq valuelist (vlax-variant-value value))
    )
  );;;;cond
  valuelist
)

  (defun getdata2() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
    (setq ssd0  (get_tile "d0"))
    (setq ssd1  (atof(get_tile "d1")))
    (setq ssd2  (atof(get_tile "d2")))
    (setq ssd3  (atof(get_tile "d3")))
    (setq ssd4  (atof(get_tile "d4")))
    (setq ssd5  (atof(get_tile "d5")))
    (setq ssd6  (atof(get_tile "d6")))
    (setq ssd7  (atof(get_tile "d7")))
    (setq ssd8  (atof(get_tile "d8")))
		(setq ssd9  (atof(get_tile "d9")))
		(setq ssd10 (atof(get_tile "d10")))
		(setq ssd11 (atoi(get_tile "d11")))
		(setq ssd12 (atoi(get_tile "d12")))
		(setq ssd12/ (atoi(get_tile "d12/")))
		(setq ssd13 (atof(get_tile "d13")))
		(setq ssd14 (atof(get_tile "d14")))
		(setq ssd15 (atof(get_tile "d15")))
		(setq ssd16 (atof(get_tile "d16")))
	)
	
		(if (/= 'str (type ssd0))
      (progn (setq ssd0 "1")
(setq ssd1 700)(setq ssd2 650)(setq ssd3 600)(setq ssd4 600)
      (setq ssd5 500)(setq ssd6 340)(setq ssd7 200)(setq ssd8 150)(setq ssd9 100)
			(setq ssd10 5000)(setq ssd15 148.5)(setq ssd14 350)(setq ssd16 1)
			))
		 (h-read1 "c7s")

  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "底平中变变径三通" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
  (set_tile "d0" ssd0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos ssd1 2 2));
  (set_tile "d2" (rtos ssd2 2 2));
  (set_tile "d3" (rtos ssd3 2 2));
  (set_tile "d4" (rtos ssd4 2 2));
  (set_tile "d5" (rtos ssd5 2 2));
  (set_tile "d6" (rtos ssd6 2 2));
	(set_tile "d7" (rtos ssd7 2 2));
	(set_tile "d8" (rtos ssd8 2 2));
	(set_tile "d9" (rtos ssd9 2 2));
	(set_tile "d10" (rtos ssd10 2 2));
	(if (/= ssd11 nil)
  (set_tile "d11" (rtos ssd11 2 2)));变径形式
	(if (/= ssd12 nil)
  (set_tile "d12" (rtos ssd12 2 2)))
	(if (/= ssd12/ nil)
  (set_tile "d12/" (rtos ssd12/ 2 2)));横向分料方式
  (set_tile "d13" (rtos ssd13 2 2));厚度

  (set_tile "d14" (rtos ssd14 2 2))
	(set_tile "d15" (rtos ssd15 2 2));起步长度
	(set_tile "d16" (rtos ssd16 2 2));刻线长度	 
 ;将对应key的全局变量传递给控件
  ;(mode_tile "d0" 2);设置d0为焦点
  (action_tile "accept" "(getdata2)(done_dialog 1)") ;当按下确认按钮的时候保存控件值，然后退出界面,并执行对于功能函数
  (action_tile "cancel" "(getdata2)(done_dialog 0)") ;当按下取消按钮的时候保存控件值，然后退出界面
  (action_tile "help" "(getdata2)(done_dialog 2)")
	(action_tile "EL1" "(getdata2)(done_dialog 3)")
  (setq re (start_dialog))
  (unload_dialog dcl_id)
     (cond ((= re 0)
(princ "\n单击了取消按钮")	     
          )
     ((= re 2)
(alert "\n 1、所填尺寸均为未扣除尺寸，请先扣除尺寸
       \n 2、读取excel数据需要在E盘部署本地化读取数据的文件才能读取
       \n 3、排版图决定是否直接生成排版数据
       \n 4、序号不在局限于数字可以为任意英文或字符串；
       \n 5、其他细节优化，如插入点位置等等。
	     \n 6、新增EXCEL联动自动化输入"
       )	     
          )
	((= re 3)
(test1)
		
          )		 
			 
			   
          ((= re 1)
	  (princ "\n单击了确定按钮")	  
   ;  上面是需要的变量参数
  (setq pt0(getpoint "请输入插入的位置："))
  (c7r pt0)
  ))
	(h-save1 '(ssd0 ssd1 ssd2 ssd3 ssd4 ssd5 ssd6 ssd7 ssd8 ssd9 ssd10 ssd11 ssd12 ssd12/ ssd13 ssd14 ssd15 ssd16) "c7s" )
    (setvar "osmode" 16383)  ;打开对象捕捉状态
	
  (command "._undo" "_end")))
  (princ) ;静默退出
	)

;马口等径三通 C7B
(defun c:c7b(/ d8 make_mkdjst_dcl p1 p10 p10a p11 p11a p12 p12a p13 p13a p14 p14a p15 p15a p16 p16a p17 p18 p19 p1a p2 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p2a p3 p30 p31 p3a p4 p4a p5 p5a p6 p6a p7 p7a p8 p8a p9 p9a pt0);焊接马口等径三通
	(defun make_MKDJST_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "马口等径三通:dialog { //定义名字为德国项目支架的对话框"
 "     label= \"马口等径三通\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"主管长          (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d0\";//编辑框1的关键字"
  "               mnemonic = \"d0\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"主管宽(马口面）(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"主管高         (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口长        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口高        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口直段      (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口偏量      (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口距边     (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d7\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
		
	   "     :row{ //引用行"
  "           :popup_list{ //引用编辑框1"	
  "               label=\"携带盲板     (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d8\";//编辑框1的关键字"
	"               list=\"带\\n不带\";is_tab_stop=false;"				
  "            }} //编辑框1引用结束"					
					
					
	 
             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
	
  (setq file (vl-filename-mktemp "DclTemp-MKDJST.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
   (command "._undo" "_begin")
  (setq Keys '("d0" "d1" "d2" "d3" "d4" "d5" "d6" "d7" "d8"))
  (if (not c7bd0)
  (progn
  (setq c7bd0 1797 c7bd1 947)
  (setq c7bd2 1497 c7bd3 897)
  (setq c7bd4 198.5 c7bd5 48.5)
  (setq c7bd6 150 c7bd7 98.5   c7bd8 0);设变量初值
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_MKDJST_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "马口等径三通" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list (rtos c7bd0 2 2)
                   (rtos c7bd1 2 2)  (rtos c7bd2 2 2)
		   (rtos c7bd3 2 2)  (rtos c7bd4 2 2)
		   (rtos c7bd5 2 2)  (rtos c7bd6 2 2)
		   (rtos c7bd7 2 2)  (rtos c7bd8 2 2)

		   )
    )
    ;设置d1为焦点
    (mode_tile "d0" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c7b\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
(setq pt0(getpoint"请点击插入的位置:"))
  (setq d8(sqrt (+ (* (- c7bd4 c7bd5) (- c7bd4 c7bd5)) (* c7bd6 c7bd6))))
 ;上列为获取数据
(setq p1(list (car pt0) (+ (cadr pt0) c7bd7));马口距边距离
      p2(list (- (car p1) c7bd4) (cadr p1));
      p3(list (car p2) (+ (cadr p2) c7bd3))
      p4(list (+ (car p3) c7bd5) (cadr p3))
      p5(list (car p1) (+ (cadr p4) c7bd6))
      p6(list (car p5) (+ (cadr p5) (- c7bd2 c7bd7 c7bd3 c7bd6)))
      p7(list (+ (car p6) c7bd0) (cadr p6))
      p8(list (+ (car p7) c7bd1) (cadr p7))
      p9(list (+ (car p8) c7bd0) (cadr p8))
      p10(list(car p9) (cadr p5))
      p11(list(+ (car p10) (- c7bd4 c7bd5)) (cadr p4))
      p12(list(+ (car p11) c7bd5) (cadr p3))
      p13(list(car p12) (cadr p2))
      p14(list(- (car p13) c7bd4) (cadr p1))
      p15(list(car p14) (cadr pt0))
      p16(list(car p8) (cadr pt0))
      p17(list(car p7) (cadr pt0)))
  (command "line" pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 "c")
(setq p1a(list (car p1) (+ (cadr p1) 1))
      p2a(list (car p4) (- (cadr p4) 1))
      p3a(list (car p5) (- (cadr p5) 1))
      p4a(list (car p7) (- (cadr p7) 1))
      p5a(list (car p8) (- (cadr p8) 1))
      p6a(list (car p10) (- (cadr p10) 1))
      p7a(list (car p11) (- (cadr p11) 1))
      p8a(list (car p14) (+ (cadr p14) 1))
      p9a(list (car p16) (+ (cadr p16) 1))
      p10a(list (car p17) (+ (cadr p17) 1)))
  (command "color" 2)
  (command "line" p1 p1a "")(command "line" p4 p2a "")
  (command "line" p5 p3a "")(command "line" p7 p4a "")
  (command "line" p8 p5a "")(command "line" p10 p6a "")
  (command "line" p11 p7a "")(command "line" p14 p8a "")
  (command "line" p16 p9a "")(command "line" p17 p10a "")
  (command "color" 1)
  (command "layer" "S" "3中心线层" "")
  (command "line" p7 p17 "")(command "line" p8 p16 "");绘制中心线
  (command "color" "byblock")
  (command "layer" "S" "1轮廓层" "")
  (command "-DIMSTYLE" "R" "m-8")
  (setvar "dimtix" 1) ;强制尺寸文本在两尺寸界线之内
  (command "dimlinear" pt0 p1 "@-50,50")
  (command "dimlinear" p1 p2 "@50,150")
  (command "dimlinear" p2 p3 "@-100,-250")
  (command "dimlinear" p3 p4 "@-50,100")
  (command "dimlinear" p4 p5 "@150,-100")
  (command "dimlinear" p5 p6 "@100,-100")
  (command "-DIMSTYLE" "R" "m-15") 
  (command "dimlinear" p6 p7 "@-150,50")
  (command "dimlinear" p7 p8 "@-150,50")
  (command "dimlinear" p8 p9 "@-150,50")
  (command "dimlinear" p6 p9 "@-150,350")
  ;上面为主管部分
  (setq 
        p18 (list (+ (car p13) 500) (cadr p15))
	p18a (list (car p18) (- (cadr p18) c7bd0))
	
	p19 (list (car p18) (+ (cadr p18) c7bd7))
	p20 (list (car p19) (+ (cadr p19) c7bd4))
	p21 (list (+ (car p20) c7bd1) (cadr p20))
	p21a (list (car p21) (cadr p18a))
	p22 (list (car p21) (cadr p19))
	p23 (list (car p21) (cadr p18)))
	(if (= c7bd8 0)
		(progn
		(MK-line (list p18a p18 p19 p20 p21 p22 p23 p21a))
		(entmake (list '(0 . "LINE") (cons 10 p18) (cons 11 p23)(cons 62 1)(cons 8 "3中心线层")))
		(line1 p18 1)	(line1 p23 2)
		(dim p18 p18a 2 -30)
		)	
		(MK-line (list p18 p19 p20 p21 p22 p23 ))
		)
		
		
		
  ;(command "line" p18a p18 p19 p20 p21 p22 p23 p21a "C")
  (setq p11a(list (+ (car p19) 1) (cadr p19))
	p12a(list (- (car p22) 1) (cadr p22))
	p19a(list (- (car p23) 1) (cadr p23))
	p20a(list (+ (car p18) 1) (cadr p18)))
  (command "color" 2)
  (command "line" p19 p11a "")(command "line" p22 p12a "")
  
  (command "color" 1)
  (command "layer" "S" "3中心线层" "")
  (command "line" p19 p22 "")
  
  (command "color" "byblock")
  (command "layer" "S" "1轮廓层" "")
  (command "-DIMSTYLE" "R" "m-8")
  (setvar "dimtix" 1)
  (command "dimlinear" p18 p19 "@-50,-50")
  (command "dimlinear" p19 p20 "@-50,-50")
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimlinear" p20 p21 "@-110,50")
;上面是支管 部分1
(setq p24(list (car p20) (+ (cadr p20) 400))
      p25(list (car p24) (+ (cadr p24) c7bd5))
      p26(list (car p25) (+ (cadr p25) d8))
      p27(list (car p26) (+ (cadr p26) (- c7bd2 c7bd7 c7bd3 c7bd6)))
      p28(list (+ (car p27) c7bd1) (cadr p27))
      p29(list (car p28) (cadr p26))
      p30(list (car p29) (cadr p25))
      p31(list (car p30) (cadr p24)))
  (command "line" p24 p25 p26 p27 p28 p29 p30 p31 "c")
  (setq p13a(list (+ (car p25) 1) (cadr p25))
	p14a(list (+ (car p26) 1) (cadr p26))
	p15a(list (- (car p29) 1) (cadr p29))
	p16a(list (- (car p30) 1) (cadr p30)))
  (command "color" 2)
  (command "line" p25 p13a "")(command "line" p26 p14a "")
  (command "line" p29 p15a "")(command "line" p30 p16a "")
(command "color" 1)
  (command "layer" "S" "3中心线层" "")
  (command "line" p25 p30 "") (command "line" p26 p29 "");绘制中心线
  (command "color" "byblock")
  (command "layer" "S" "1轮廓层" "")
  (command "-DIMSTYLE" "R" "m-8")
  (setvar "dimtix" 1)
  (command "dimlinear" p24 p25 "@-50,-50")
  (command "dimlinear" p29 p30 "@150,50")
  (command "dimlinear" p26 p27 "@-50,-50")
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimlinear" p27 p28 "@-150,50")))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
  (princ) ;静默退出
  )

;方反弯展开 C8
(defun c:c8(/ d10 d11 d12 d13 d14 d15 d16 d17 make_ffwzk_dcl p1 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p2 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p3 p30 p31 p32 p33 p34 p35 p36 p37 p4 p5 p6 p7 p8 p9 s1 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s2 s20 s21 s22 s23 s24 s3 s4 s5 s6 s7 s8 s9 w1 x1) ;反弯展开放样
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
   (command "._undo" "_begin")
(defun make_FFWZK_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "方反弯展开:dialog { //定义名字为底平中变变径三通的对话框"
 "     label= \"方反弯展开\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"序号      (个)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "               mnemonic = \"d1\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头宽    (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头深    (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"中间直段  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头下伸量(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"弯头上伸量(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 	 	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"入口半径  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d7\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"出口半径  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d8\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-FFWZK.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
  (setq Keys '("d1" "d2" "d3" "d4" "d5" "d6" "d7" "d8"))
  (if (not c8d2)
  (progn
  
  (setq c8d1 1 c8d2 297)
  (setq c8d3 497 c8d4 300)
  (setq c8d5 78.5)
  (setq c8d6 48.5)
  (setq c8d7 101.5)
  (setq c8d8 101.5)
  ;设变量初值
  
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_FFWZK_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "方反弯展开" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list
                   (rtos c8d1 2 2)  (rtos c8d2 2 2)
		   (rtos c8d3 2 2)  (rtos c8d4 2 2)
		   (rtos c8d5 2 2)  (rtos c8d6 2 2)
		   (rtos c8d7 2 2)  (rtos c8d8 2 2)
		   )
    )
    ;设置d1为焦点
    (mode_tile "d1" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c8\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
(setq pt0(getpoint "插入点"))
;  上面是需要的变量参数
  (setq d10 90);固定弯头角度（保持不变）
  (setq d11(/ (* d10 pi c8D8) 180));出口短弧长
  (setq d12(/ (* d10 pi c8D7) 180));入口短弧长
  (setq d13(/ (* d10 pi (+ c8D8 c8D2)) 180));出口长弧长
  (setq d14(/ (* d10 pi (+ c8D7 c8D2)) 180));入口长弧长
  (if (>= c8D2 1000) (setq d3 60) (setq d3 50))
  (setq d15(+ c8D4 (* d3 2) ));中间直段的长度
;上面的为需要的固定参数
;编程开始：下面为底部料片
(setq p1(list (+ (car pt0) c8D3) (cadr pt0));入口深
      p2(list (car p1) (+ (cadr p1) c8D5));入口伸量
      p3(list (car p2) (+ (cadr p2) d12));入口短弧长
      p4(list (car p3) (+ (cadr p3) d15));中间直段的长度
      p5(list (car p4) (+ (cadr p4) d13));出口长弧长
      p6(list (car p5) (+ (cadr p5) c8D6));出口半径
      p7(list (car pt0) (cadr p6));出口深
      p8(list (car pt0) (cadr p5))
      p9(list (car pt0) (cadr p4))
      p10(list (car pt0) (cadr p3))
      p11(list (car pt0) (cadr p2)))
  (command "line"  pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 "c")
  ;上面为底部料片制作数据
(setq s1(list (- (car p2) 1) (cadr p2))
      s2(list (- (car p3) 1) (cadr p3))
      s3(list (- (car p4) 1) (cadr p4))
      s4(list (- (car p5) 1) (cadr p5))
      s5(list (+ (car p8) 1) (cadr p8))
      s6(list (+ (car p9) 1) (cadr p9))
      s7(list (+ (car p10) 1) (cadr p10))
      s8(list (+ (car p11) 1) (cadr p11)))
 (command "line" p2 s1 "") (command "line" p3 s2 "")
 (command "line" p4 s3 "") (command "line" p5 s4 "")
 (command "line" p8 s5 "") (command "line" p9 s6 "")
 (command "line" p10 s7 "") (command "line" p11 s8 "")
 ;第一片料打点数据
 (command "-DIMSTYLE" "R" "m-8")
 (command "dimlinear" p6 p7 "h" "@-150,50")
 (command "dimlinear" p1 p2 "v" "@100,-150")
 (command "dimlinear" p4 p5 "v" "@100,-150");出口长弧长
 (command "dimlinear" p7 p8 "v" "@-50,150");出口伸量
 (command "dimlinear" p9 p10 "v" "@-50,150");直段长度
 (command "dimlinear" p10 p11 "v" "@-50,150")
  ;第一片料结束，下面为第二片料
(setq p12(list (+ (car p1) 1000) (cadr p1))
      p13(list (+ (car p12) c8D3) (cadr p12))
      p14(list (car p13) (+ (cadr p13) c8D5));入口伸量
      p15(list (car p14) (+ (cadr p14) d14));入口长弧长
      p16(list (car p15) (+ (cadr p15) d15));直段长度
      p17(list (car p16) (+ (cadr p16) d11));出口短弧长
      p18(list (car p17) (+ (cadr p17) c8D6));出口伸量
      p19(list (car p12) (cadr p18));出口深
      p20(list (car p19) (cadr p17))
      p21(list (car p20) (cadr p16))
      p22(list (car p21) (cadr p15))
      p23(list (car p22) (cadr p14)))
(command "line" p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 "c")
  ;上面为顶部料片制作数据
  (setq s9(list (- (car p14) 1) (cadr p14))
      s10(list (- (car p15) 1) (cadr p15))
      s11(list (- (car p16) 1) (cadr p16))
      s12(list (- (car p17) 1) (cadr p17))
      s13(list (+ (car p20) 1) (cadr p20))
      s14(list (+ (car p21) 1) (cadr p21))
      s15(list (+ (car p22) 1) (cadr p22))
      s16(list (+ (car p23) 1) (cadr p23)))
 (command "line" p14 s9 "") (command "line" p15 s10 "")
 (command "line" p16 s11 "") (command "line" p17 s12 "")
 (command "line" p20 s13 "") (command "line" p21 s14 "")
 (command "line" p22 s15 "") (command "line" p23 s16 "")
  ;顶部料片打点数据
 (command "dimlinear" p18 p19 "h" "@-150,50")
  (command "dimlinear" p14 p15 "v" "@100,-150")
  (command "dimlinear" p20 p21 "v" "@-50,150")
  ;顶部料片结束，开始右边料片制作
(setq p24(list (car p18) (+ (cadr p18) 500))
      p25(list (car p24) (+ (cadr p24) c8D5));内圆弧起点
      p26(list (- (car p25) c8D7) (cadr p25));圆弧圆心
      p27(list (car p26) (+ (cadr p26) c8D7));圆弧端点
      p28(list (- (car p27) d15) (cadr p27));直段长度,外圆弧起点
      p29(list (car p28) (+ (cadr p28)  c8D2 c8D8));外圆弧圆心
      p30(list (- (car p29) c8D2 c8D8) (cadr p29));外圆弧端点
      p31(list (car p30) (+ (cadr p30) c8D6))
      p32(list (+ (car p31) c8D2) (cadr p31))
      p33(list (car p32) (Cadr p30))
      p34(list (car p28) (+ (cadr p28) c8D2))
      p35(list (+ (car p34) d15) (cadr p34))
      p36(list (+ (car p25) c8D2) (Cadr p25))
      p37(list (car p36) (- (cadr p36) c8D5)))
(command "line" p25 p24 p37 p36 "")(command "arc" p25 "c" p26  p27)
(command "line" p27 p28 "")(command "arc" p30 "c" p29  p28)
(command "line" p30 p31 p32 p33 "")(command "arc" p33 "c" p29  p34)
(command "line" p34 p35 "")(command "arc" p36 "c" p26  p35)
;上面为右边料片制作数据
(setq s17(list (+ (car p25) 1) (cadr p25))
      s18(list (car p27) (+ (cadr p27) 1))
      s19(list (car p28) (+ (cadr p28) 1))
      s20(list (+ (car p30) 1) (cadr p30))
      s21(list (- (car p33) 1) (cadr p33))
      s22(list (car p34) (- (cadr p34) 1))
      s23(list (car p35) (- (cadr p35) 1))
      s24(list (- (car p36) 1) (cadr p36)))
 (command "line" p25 s17 "")(command "line" p27 s18 "")
 (command "line" p28 s19 "")(command "line" p30 s20 "")
 (command "line" p33 s21 "")(command "line" p34 s22 "")
 (command "line" p35 s23 "")(command "line" p36 s24 "")
;右部料片打点数据
(command "dimlinear" p32 p31 "h" "@-150,50")
(command "dimlinear" p34 p35 "h" "@-150,50")
(command "dimlinear" p34 p33 "h" "@-150,-350")
(command "dimlinear" p36 p37 "v" "@100,-150")
(command "dimlinear" p25 p27 "h" "@-50,-200")



(setq pt1(list (+ (car p37) 300) (- (cadr p37) 300)));框选点1
(setq pt2(list (- (car p31) 250) (+ (cadr p31) 250)));框选点2
(setq pt3(list (- (car p31) 400) (cadr p31)));镜像点1 
(setq pt4(list (car pt3) (+ (cadr pt3) 100)));镜像点2
(setq x1(ssget "_w" pt2 pt1))
(command "mirror" x1 "" pt3 pt4 "n")
(setq d17(rtos c8D1 2 2))


  (command "color" 1)
  (setq w1(list (/ (+ (car p27) (car p35)) 2) (/ (+ (cadr p27) (cadr p35)) 2)))
  (command "text" "m" (list (- (car w1) (* (+ c8D2 400 d15 c8D8) 2)) (cadr w1)) 100 0(strcat d17 "/1"));序号标注1
  (command "text" "m" (list (/ (+ (car p4) (car p9)) 2) (/ (+ (cadr p4) (cadr p9)) 2)) 100 0(strcat d17 "/3"));序号标注3
  (command "text" "m" (list (/ (+ (car p16) (car p21)) 2) (/ (+ (cadr p16) (cadr p21)) 2)) 100 0(strcat d17 "/4"));序号标注4
  (command "text" "m" (list (/ (+ (car p27) (car p35)) 2) (/ (+ (cadr p27) (cadr p35)) 2)) 100 0(strcat d17 "/2"));序号标注2
  (command "color" 7)))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;正圆台展开 Y2
(defun c:y2(/ dcl_file dcl_id getdata1 make-dclcs pt0 re y2 y2d0 y2d1 y2d2 y2d3 y2d4 y2d5 y2t)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "正圆台展开:dialog"
				 "{ // start dcl"
				 "label = \"正圆台展开\";"	
         ":row{"
         ":boxed_column{label = \"交互参数\";"			 
				 ":edit_box{label=\"管件序号:          \";key=\"d0\";}";编辑框
				 ":edit_box{label=\"圆台大口直径:      \";key=\"d1\";}";编辑框
				 ":edit_box{label=\"圆台小口直径:      \";key=\"d2\";}";编辑框
				 ":edit_box{label=\"圆台高度(去除直段):\";key=\"d3\";}";编辑框
				 ":edit_box{label=\"大口脖料长度:      \";key=\"d4\";}";编辑框
				 ":edit_box{label=\"小口脖料长度:      \";key=\"d5\";}}";编辑框
				 ":boxed_column{label = \"设置参数\";"
				 ":edit_box{label=\"板材厚度:\";key=\"T\";is_tab_stop=false;}";板材板厚
         ":spacer{height = 8;}}}";填补剩余间隙，使一二两列保持平行
				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
					

	(defun y2 (pt0 y2d0 y2d1 y2d2 y2d3 y2d4 y2d5 y2t / d1 d2 d3 d4 d5 d6 d7 d8 d8a p1 p2 p3 p4 pt1 s1 s2 S3 S4  s5) ;引用函数，
  (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
;下面为获取基础数据参数  
				      (setq d1 (- y2d1 y2t);d1为大口直径
								    d2 (- y2d2 y2t );d2为小口直径
								    d3 y2d3 );D3为圆台高度	
		   
	    (setq d4(/ (* d1 d3) (- d1 d2));H整体圆锥体高；h=dh/D-d
            d5(sqrt(+ (* d4 d4) (/ (* d1 d1) 4)));R整体圆锥展开半径： R=SQRT (H2+D2/4)
				    d6(- d4 d3);h1 圆锥上半部分长度
				    d7(/ (* d6 d5) d4);r 圆锥上半部展开半径
            d8(/ (* pi d1) d5 2);a 展开料夹角弧度a=pi*d1/R1;这里直接将角度转成弧度系数了，角度=弧度/180/pi
				    d8a(* d8 -1))
;下面为开始绘制圆台数据
	   (setq  pt1(polar pt0 pi  d7 )
	          p1(polar pt1 d8a d7)
	          p2(polar pt1 d8 d7)
	          p3(polar pt1 d8a d5)
	          p4(polar pt1 d8 d5))
	(setq s1 (mk-arc pt1 p1 p2)
        s2 (mk-arc pt1 p3 p4))
	(dar p1 p2 pt1 200)(dar p3 p4  pt1 200) 
	(mk-line1 (list p1 p3))(mk-line1 (list p2 p4))
  (dal p2 p4 (list (car p2) (+ (cadr p4) 50)))
(setq s3 (MK-Curve-getDIVPoints s1 4 0))
(setq s4 (MK-Curve-getDIVPoints s2 4 0))
(setq s5 (cadr s3)) (setq s6 (cadr s4))
(text (strcat y2d0 "/1")  (list (+ (car s5) (/ (- (car s6) (car s5)) 2)) (cadr s5)) 200 1 1 "0")	
(mapcar (function (lambda (p1 p2)
	(entmakex (list '(0 . "line") (cons 10 p1) (cons 62 2) (cons 11 (polar p1 (angle p1 p2)1))))
	(entmakex (list '(0 . "line") (cons 10 p2) (cons 62 2) (cons 11 (polar p2 (angle p1 p2) -1))))	
  (entmakex (list '(0 . "line") (cons 10 p1) (cons 62 1) (cons 8 "3中心线层")(cons 11 p2)))										
	))   s3 s4)
;下面开始绘制大口直段
		(setq pt2 (list (- (car p1) 500) (cadr p1))
	        pt3 (list (- (car pt2) y2d4 500) (cadr p1)))
(if (/= y2d4 0)
(progn	    
	    (mk-box pt2 (* y2d4 -1) (* d1 pi) 0)
	 (text (strcat y2d0 "/2" ) (list (- (car pt2) (/ y2d4 2)) (+ (cadr pt2) (/ (* d1 pi)2) ))   100 1 1 "0")
  ))
(if (/= y2d5 0)
(progn	    
	    (mk-box pt3 (* y2d5 -1) (* d2 pi) 0)
	(text (strcat y2d0 "/3" ) (list (- (car pt3) (/ y2d5 2)) (+ (cadr pt2) (/ (* d2 pi)2) ))   100 1 1 "0")
))
	(text (strcat "圆台大口直径" (rtos y2d1)) (list (car pt3) (- (cadr pt2) 200))   100 7 0 "序号图层")
	(text (strcat "圆台小口直径"(rtos y2d2)) (list (car pt3) (- (cadr pt2) 350))   100 7 0 "序号图层")
	(text (strcat "圆台高度为(不含直段)"(rtos y2d3)) (list (car pt3) (- (cadr pt2) 500))   100 7 0 "序号图层")
	(text (strcat "大口脖料长度"(rtos y2d4)) (list (car pt3) (- (cadr pt2) 650))   100 7 0 "序号图层")
	(text (strcat "小口脖料长度"(rtos y2d5)) (list (car pt3) (- (cadr pt2) 800))   100 7 0 "序号图层")

   (command "._undo" "_end")
(setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ))
	;;---------开始写面板调用函数
	(if (/= 'str (type y2d0))
		(progn (setq y2d0 "1")
			
      (setq y2d1 1250)(setq y2d2 1200)(setq y2d3 1997)(setq y2d4 0)
			(setq y2d5 200)(setq y2t 1.5)

		))
	
	(h-read1  "y2");读取注册表的数据
	(defun getdata1()
		(setq 
			y2d0 (get_tile "d0")
			y2d1 (atof (get_tile "d1"))
			y2d2 (atof (get_tile "d2"))
			y2d3 (atof (get_tile "d3"))
			y2d4 (atof (get_tile "d4"))
			y2d5 (atof (get_tile "d5"));分料数据
			y2t (atof (get_tile "T"));分料数据
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "正圆台展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	(set_tile "d0" y2d0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos y2d1 2 2))
  (set_tile "d2" (rtos y2d2 2 2))
  (set_tile "d3" (rtos y2d3 2 2))
	(set_tile "d4" (rtos y2d4 2 2 ))
	(set_tile "d5" (rtos y2d5 2 2 ))
	(set_tile "T" (rtos y2t 2 2 ))
	
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "\n1、插入点位置由变径圆心改为变径小口中心点；
                  2、新增变径4等分打点；
                  3、常用变量存储注册表，减少全局变量导致的卡顿；
                  4、重构代码，提高运行速度；
                  5、增加序号，同时解决当大小口直段为0时，绘制0宽短脖问题。
"
					
				)	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint"请选择图形插入点"))
				(y2  pt0 y2d0 y2d1 y2d2 y2d3 y2d4 y2d5 y2t)				
			))	
	)	
	
	(h-save1  '(y2d0 y2d1 y2d2 y2d3 y2d4 y2d5 y2t) "y2");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;圆法兰展开 YF
(defun c:yf (/ d6 d7 d8 e1 e2 e3 e4 make_yfl_dcl p1 p2 pt0 pt1 pt2 pt3);圆法兰不规则下料
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
	(defun make_YFL_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "圆法兰:dialog { //定义名字为圆法兰"
 "     label= \"圆法兰\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"法兰内径  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "               mnemonic = \"d1\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"中心距    (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"法兰宽度    (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"开孔直径  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"开孔数量  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	 	 	 
             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-YFL.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
  (setq Keys '("d1" "d2" "d6" "d4" "d5" ))
  (if (not YFLd1)
  (progn
  
  (setq yfld1 151 yfld2 191)
  (setq yfld6 40 yfld4 10)
  (setq yfld5 8.0)
  ;设变量初值
  
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_YFL_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "圆法兰" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list
                   (rtos yfld1 2 2)  (rtos yfld2 2 2)
		   (rtos yfld6 2 2)  (rtos yfld4 2 2)
		   (rtos yfld5 2 2)
		   )
    )
    ;设置d1为焦点
    (mode_tile "d1" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"yfl\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
;  上面是需要的变量参数

  
  (setq d3 (+ yfld1 (* 2 yfld6)))
  
  (SETQ D8(/ (/ 360 yfld5) 2));分线角度
  (setq d7(/ d3 2))
  (SETQ pt0(getpoint "\n 插入点："))
  (command "color" 7)
;上面为所需变量
  (command "circle" pt0 "d" yfld1);内圆
  (setq e4(entlast))
    (setq p2 (polar pt0 (/ pi 4) (/ yfld1 2)));直径标注
    (command "_dimdiameter" p2 "@-150,30")
  (command "circle" pt0 "d" yfld2);中心圆
  (setq e1(entlast))
    (command "_dimdiameter" p2 "@50,70")
  (command "circle" pt0 "d" d3);外圆
  (command "_dimdiameter" p2 "@200,100")
  (setq p1(list (car pt0) (+ (cadr pt0) d7)));外圆半径点	 
  (setq pt1(list (car pt0) (+ (cadr pt0) (/ yfld2 2))))
  (setq pt2(list (car pt0) (+ (cadr pt0) (/ yfld1 2))))
  (command "circle" pt1 "d" yfld4)
  (setq e2(entlast))
(setq d9(fix yfld5))
(command "_.ARRAY" e2 "" "P" pt0 d9  "" "")

(setq ne (strcat (itoa d9) "*" "<>"))
(command "_dimdiameter" p2 "@-50,-50");在d5标注之后，对标注进行修改
(setq dlitxt (entget (entlast)))
(setq dlitxt  (subst (cons 1 ne) (assoc 1 dlitxt) dlitxt))
(entmod dlitxt);



	   



	   
  
  (command "erase" e1 "")
  (command "line" pt2 p1 "")
  (setq e3(entlast))
  (command "rotate" e3 "" pt0 d8)
  (if
    (>= yfld1 160)
  (progn
  (if
    (<= yfld1 506)
  (progn
  (command "rotate" e3 "" pt0 "c" 120)
  (command "rotate" e3 "" pt0 "c" 240)
  )
  (progn
  (command "rotate" e3 "" pt0 "c" 90)
  (command "rotate" e3 "" pt0 "c" 180)
  (command "rotate" e3 "" pt0 "c" 270)
  (command "rotate" e3 "" pt0 "c" 360)))
  )
    (command "erase" e3 "" ))
(setq d10(rtos yfld1 2 2))
(setq d11(rtos yfld2 2 2))
(setq d12(rtos yfld6 2 2))
(setq d13(rtos yfld4 2 2))
(setq d14(rtos yfld5 2 2))


  (command "color" 7)
  (command "layer" "S" "序号图层" "")
  (command "text" "m" (list (car pt0) (- (cadr pt0) d3 300)) 100 0(strcat "法兰内径为  "  d10 ));法兰内径
  (command "text" "m" (list (car pt0) (- (cadr pt0) d3 500)) 100 0(strcat "法兰中心距为"  d11 ));中径
  (command "text" "m" (list (car pt0) (- (cadr pt0) d3 700)) 100 0(strcat "法兰宽度为"  d12 ));宽度
  (command "text" "m" (list (car pt0) (- (cadr pt0) d3 900)) 100 0(strcat "开孔大小为"  d13 ));开孔
  (command "text" "m" (list (car pt0) (- (cadr pt0) d3 1100)) 100 0(strcat "开孔数量为"  d14 ));开孔数量
  (command "layer" "S" "0" "")
	   ))
    (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;方法兰展开参数版 FFL1
(defun c:ffl1(/  p1 p2 p3 p4 p5 p6 p7 p8 p9 s1 pt0 pt1 pt2 
	       n1 pd1 pd2 p10 p11 p12 p13 e1 e2 );方法兰下料
	(defun make_FFLZK_dcl (/ lst_str str file f)
  (setq lst_str
        (list
 "方法兰放样:dialog { //定义名字为方法兰一键展开的对话框"
 "     label= \"方法兰放样\";//显示在对话框顶部的标签"
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰内径长(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "               mnemonic = \"d1\";//编辑框1的热键"
  "            }} //编辑框1引用结束"
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰内径宽(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "               mnemonic = \"d2\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰中径长(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰中径宽(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

    "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰外径长(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

 
     "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰外径宽(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

      "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"法兰开孔大小(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d7\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

       "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"法兰长边等分间距(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d8\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

 
       "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"法兰宽边等分间距(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d9\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-FFLZK.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
    (setq Keys '("d1" "d2" "d3" "d4" "d5" "d6" "d7" "d8" "d9"))
  (if (not ffld1)
   ( progn
    (setq ffld1 401 ffld2 301)
    (setq ffld3 421 ffld4 321)
    (setq ffld5 441 ffld6 341)
    (setq ffld7 10 ffld8 75)
    (setq ffld9 75))
    )
  
    ;加载DCL对话框
    (setq DcLwjm (make_FFLZK_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "方法兰放样" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list (rtos ffld1 2 2) (rtos ffld2 2 2)
		   (rtos ffld3 2 2) (rtos ffld4 2 2)
		   (rtos ffld5 2 2) (rtos ffld6 2 2)
		   (rtos ffld7 2 2) (rtos ffld8 2 2)
		   (rtos ffld9 2 2)
		   )
    )
    ;设置d1为焦点
    (mode_tile "d1" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"ffl\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")

              ;显示两编辑框中取得数值
              (princ "\n ffld1=")(princ ffld1)
              (princ "   ffld2=")(princ ffld2)
	      (princ "   ffld3=")(princ ffld3)
              (princ "   ffld4=")(princ ffld4)
	      (princ "   ffld5=")(princ ffld5)
	      (princ "   ffld6=")(princ ffld6)
	      (princ "   ffld7=")(princ ffld7)
	      (princ "   ffld8=")(princ ffld8)
	      (princ "   ffld9=")(princ ffld9)
              ; 这里加入进行相应的处理部分

(SETQ pt0(getpoint "插入点："))

(setq p1(list (car pt0) (+ (cadr pt0) ffld2)) p2(list (+ (car p1) ffld1) (cadr p1)));
(setq p3(list (car p2) (- (cadr p2) ffld2)))
(command "pline" pt0 p1 p2 p3 "c")
(dim pt0 p1 2 30)  (dim p1 p2 1 30)
(setq s1(/ (- ffld3 ffld1) 2));
(setq s2(/ (- ffld4 ffld2) 2));
(setq s3(/ (- ffld5 ffld3) 2))
(setq s4(/ (- ffld6 ffld4) 2))
(setq pt1(list (- (car pt0) s1) (- (cadr pt0) s2)))
(setq p4(list (car pt1) (+ (cadr pt1) ffld4)) p5(list (+ (car p4) ffld3) (cadr p4)))
(setq p6(list (car p5) (cadr pt1)))
(command "pline" pt1 p4 p5 p6 "c")
(setq e1(entlast))
(setq pt2(list (- (car pt1) s3) (- (cadr pt1) s4)))
(setq p7(list (car pt2) (+ (cadr pt2) ffld6)) p8(list (+ (car p7) ffld5) (cadr p7)))
(setq p9(list (car p8) (cadr pt2)))
(command "pline" pt2 p7 p8 p9 "c")
(setq e2(entlast))							  
(command "fillet" "r" 5)
(command "fillet" "p" e2);倒左下圆角

(command "circle" pt1 "d" ffld7 "") (command "circle" p4 "d" ffld7 "")
(command "circle" p5 "d" ffld7 "") (command "circle" p6 "d" ffld7 "")
 (setq n1(fix(/ ffld3 ffld8)))
    (if(< (* 0.5 (- ffld3 (* n1 ffld8))) (/ ffld8 2))
                 (setq n1(- n1 1))
        )
 (setq pd1(* 0.5 (- ffld3 (* n1 ffld8))));距离端点圆的距离
(setq p10(polar p4 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p10) (cons 40  (/ ffld7 2))))
                (setq p10(polar p10 0 ffld8))               
        )
(setq p11(polar pt1 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p11) (cons 40  (/ ffld7 2))))
                (setq p11(polar p11 0 ffld8))               
        )
 (setq n2(fix(/ ffld4 ffld9)))
    (if(< (* 0.5 (- ffld4 (* n2 ffld9))) (/ ffld9 2))
                 (setq n2(- n2 1))
        )
 (setq pd2(* 0.5 (- ffld4 (* n2 ffld9))));距离端点圆的距离
(setq p12(list(car pt1) (+ (cadr pt1) pd2)))
    (repeat (+ n2 1)
                (command "circle" p12 "d" ffld7 "")
                (setq p12(list (car p12) (+ (cadr p12) ffld8)))               
        )
(setq p13(list(car p6) (+ (cadr p6) pd2)))
    (repeat (+ n2 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p13) (cons 40  (/ ffld7 2))))
                (setq p13(list (car p13) (+ (cadr p13) ffld9)))               
        )
    (command "erase" e1 "")))
  
    (unload_dialog dcl_id)
    (vl-file-delete DCLwjm)
  


    
 


    (setvar "osmode" 16383)  ;打开对象捕捉状态
    (command "._undo" "_end")
   ;静默退出
  
  )

;福伊特方法兰下料 FF
(defun c:ff(/ dcl_id dclwjm do_what e1 e2 ffd4 ffd5 ffd6 ffd7 ffd8 ffd9 ffdd ffds keys make_ffl_dcl n1 n2 p1 p10 p11 p12 p13 p2 p3 p4 p5 p6 p7 p8 p9 pd1 pd2 pt0 pt1 pt2 s1 s2 s3 s4);方法兰下料
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
	(defun make_FFL_dcl (/ lst_str str file f)
  (setq lst_str
        (list
 "福伊特方法兰:dialog { //定义名字为方法兰一键展开的对话框"
 "     label= \"福伊特方法兰\";//显示在对话框顶部的标签"
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰内径长(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "               mnemonic = \"d1\";//编辑框1的热键"
  "            }} //编辑框1引用结束"
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰内径宽(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "               mnemonic = \"d2\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"方法兰宽度  (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

      
             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-FFL.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
    (setq Keys '("d1" "d2" "d3"))
  (if (not ffd1)
   ( progn
    (setq ffd1 901 ffd2 501)
    (setq ffd3 50 ))
    )
  
    ;加载DCL对话框
    (setq DcLwjm (make_FFL_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "福伊特方法兰" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list (rtos ffd1 2 2) (rtos ffd2 2 2)
		   (rtos ffd3 2 2)

		   )
    )
    ;设置d1为焦点
    (mode_tile "d1" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"ff\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
(if (= ffd3 40)
  (setq ffdd 20)
  (progn
 (if(= ffd3 50)
   (setq ffdd 30)(setq ffdd 35))))

(setq ffds(+ ffd1  (* ffdd 2)))
(setq ffd4(+ ffd2  (* ffdd 2)))
(setq ffd5(+ ffd1 (* ffd3 2)))
(setq ffd6(+ ffd2 (* ffd3 2)))
(if (= ffd3 40) (setq ffd7 10) (setq ffd7 12))
(setq ffd8 125)(setq ffd9 125)

(SETQ pt0(getpoint "插入点："))

(setq p1(list (car pt0) (+ (cadr pt0) ffd2)) p2(list (+ (car p1) ffd1) (cadr p1)));
(setq p3(list (car p2) (- (cadr p2) ffd2)))
(command "pline" pt0 p1 p2 p3 "c")
(setq s1(/ (- ffds ffd1) 2));
(setq s2(/ (- ffd4 ffd2) 2));
(setq s3(/ (- ffd5 ffds) 2))
(setq s4(/ (- ffd6 ffd4) 2))
(setq pt1(list (- (car pt0) s1) (- (cadr pt0) s2)))
(setq p4(list (car pt1) (+ (cadr pt1) ffd4)) p5(list (+ (car p4) ffds) (cadr p4)))
(setq p6(list (car p5) (cadr pt1)))
(command "pline" pt1 p4 p5 p6 "c")
(setq e1(entlast))
(setq pt2(list (- (car pt1) s3) (- (cadr pt1) s4)))
(setq p7(list (car pt2) (+ (cadr pt2) ffd6)) p8(list (+ (car p7) ffd5) (cadr p7)))
(setq p9(list (car p8) (cadr pt2)))
(command "pline" pt2 p7 p8 p9 "c")
(setq e2(entlast))							  
(command "fillet" "r" 5)
(command "fillet" "p" e2);倒左下圆角

(command "circle" pt1 "d" ffd7 "") (command "circle" p4 "d" ffd7 "")
(command "circle" p5 "d" ffd7 "") (command "circle" p6 "d" ffd7 "")
 (setq n1(fix(/ ffds ffd8)))
    (if(< (* 0.5 (- ffds (* n1 ffd8))) (/ ffd8 2))
                 (setq n1(- n1 1))
        )
 (setq pd1(* 0.5 (- ffds (* n1 ffd8))));距离端点圆的距离
(setq p10(polar p4 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p10) (cons 40  (/ ffd7 2))))
                (setq p10(polar p10 0 ffd8))               
        )
(setq p11(polar pt1 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p11) (cons 40  (/ ffd7 2))))
                (setq p11(polar p11 0 ffd8))               
        )
 (setq n2(fix(/ ffd4 ffd9)))
    (if(< (* 0.5 (- ffd4 (* n2 ffd9))) (/ ffd9 2))
                 (setq n2(- n2 1))
        )
 (setq pd2(* 0.5 (- ffd4 (* n2 ffd9))));距离端点圆的距离
(setq p12(list(car pt1) (+ (cadr pt1) pd2)))
    (repeat (+ n2 1)
                (command "circle" p12 "d" ffd7 "")
                (setq p12(list (car p12) (+ (cadr p12) ffd8)))               
        )
(setq p13(list(car p6) (+ (cadr p6) pd2)))
    (repeat (+ n2 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p13) (cons 40  (/ ffd7 2))))
                (setq p13(list (car p13) (+ (cadr p13) ffd9)))               
        )
    (command "erase" e1 "")))
  
    (unload_dialog dcl_id)
    (vl-file-delete DCLwjm)
    (setvar "osmode" 16383)  ;打开对象捕捉状态
    (command "._undo" "_end")
   ;静默退出  
  )

;方法兰厂标版 FFL
(defun c:ffl(/ d3 d4 d5 d6 d7 d8 dcl_file dcl_id e1 e2 getdata1 make-dclcs n1 n2 p1 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p2 p20 p21 p22 p23 p3 p4 p5 p6 p7 p8 p9 pd1 pd2 pt0 pt1 pt2 re s1);方法兰下料
  (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	;动态绘制DCL面板函数
  (defun make-dclCS  (/ lst_str str file f);;面板的界面显示dcl
		(setq lst_str
			'(
				"厂标矩形法兰:dialog"
				"{ // start dcl"
				"label = \"厂标矩形法兰\";"
				":row{"
			  ":column {"			
			  ":edit_box{label=\"法兰长度(L):\";key=\"d1\";}"
				":edit_box{label=\"法兰宽度(W):\";key=\"d2\";}"
				":popup_list{label=\"分料形式(U):\";key=\"d3\";list=\"无\\nL型\\n条型\";is_tab_stop=false;}}}"					 							 
				":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}}";取消按钮
		
				"fixed_width=true;";固定宽度（?）
				 "alignment=left;";对齐方式（左对齐）
				 "} // end dll"  
			 ))
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f))		
		  (close f)
		file
	)
	(h-read1  "ffl")
(if (not fd1)
      (progn 
      (setq fd1 400)(setq fd2 300)(setq fd3 0))
		)	
(defun getdata1() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量
	  (setq
    fd1 (atof (get_tile "d1"))
    fd2 (atof (get_tile "d2"))
    fd3 (atoi (get_tile "d3"))
 ))
 (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "厂标矩形法兰" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
  (set_tile "d1" (rtos fd1 2 2));
  (set_tile "d2" (rtos fd2 2 2));
	(if (/= fd3 nil)(set_tile "d3" (rtos fd3 2)))
  (mode_tile "d1" 2)
  (action_tile "accept" "(getdata1)(done_dialog 1)") ;当按下确认按钮的时候保存控件值，然后退出界面,并执行对于功能函数
  (action_tile "cancel" "(getdata1)(done_dialog 0)") ;当按下取消按钮的时候保存控件值，然后退出界面
  (setq re (start_dialog))
  (unload_dialog dcl_id)
	 (cond ((= re 0) ;鼠标按下确认后，开始执行这里的操作
		(progn 
      (prompt"\n 用户取消绘制厂标矩形法兰！"))) ;鼠标按下确认后，将各个控件的值汇总到这里，传递给功能函数，执行功能操作	
		((= re 1)
	(progn		
  (SETQ d3(+ fd1 1) d4(+ fd2 1))
;假设条件语句，根据口径长确认法兰外径中径内径和法兰宽度
	  (IF(< fd1 1000)
		(progn (SETQ D5(+ D3 40) D6(+ D4 40)d7(+ d3 80) d8(+ d4 80) s1 20));根据口径长度调整法兰外径中径内径和法兰宽度		
		(progn (setq d5 (+ d3 50) d6 (+ d4 50) d7 (+ d3 100) d8 (+ d4 100) s1 25)))
		
(SETQ pt0(getpoint "插入点："))
(setq p1(list (car pt0) (+ (cadr pt0) d4)) p2(list (+ (car p1) d3) (cadr p1)))
(setq p3(list (car p2) (- (cadr p2) d4)))
(MK-line (list pt0 p1 p2 p3 ));内径
(dim pt0 p1 2 -50)(dim p1 p2 1 -50)
(setq pt1(list (- (car pt0) s1) (- (cadr pt0) s1)))
(setq p4(list (car pt1) (+ (cadr pt1) d6)) p5(list (+ (car p4) d5) (cadr p4)))
(setq p6(list (car p5) (cadr pt1)))
(setq pt2(list (- (car pt1) s1) (- (cadr pt1) s1)))
(setq p7(list (car pt2) (+ (cadr pt2) d8)) p8(list (+ (car p7) d7) (cadr p7)))
(setq p9(list (car p8) (cadr pt2)))
(entmake (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")'(100 . "AcDbPolyline") (cons 90 4); 顶点数               
				 (cons 10 pt2) (cons 10 p7) (cons 10 p8)(cons 10 p9)(cons 10 pt2)))	                    	
(setq e2(entlast))							  
(setvar "filletrad" 5)	(command "fillet" "p" e2);倒左下圆角	
(text (strcat (rtos fd1)"x" (rtos fd2)) (list (+ (car pt0) (/ fd1 2)) (+ (cadr pt0) (/ fd2 2)))  50 1 1 "0");规格文字
(MK-circle pt1 10 7 "0") (MK-circle p4 10 7 "0") (MK-circle p5 10 7 "0") (MK-circle p6 10 7 "0")
 (setq n1(fix(/ d5 75)))
    (if(< (* 0.5 (- d5 (* n1 75))) 37.5)
                 (setq n1(- n1 1)));根据75孔距判断n1的数量(n1为除两角的孔数)      
(setq pd1(* 0.5 (- d5 (* n1 75))));距离端点圆的距离
(setq p10(polar p4 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p10) (cons 40  5)))
                (setq p10(polar p10 0 75))               
        )
(setq p11(polar pt1 0 pd1)) 
    (repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p11) (cons 40  5)))
                (setq p11(polar p11 0 75))               
        )
 (setq n2(fix(/ d6 75)))
    (if(< (* 0.5 (- d6 (* n2 75))) 37.5)
                 (setq n2(- n2 1))
        )
 (setq pd2(* 0.5 (- d6 (* n2 75))));距离端点圆的距离
(setq p12(list(car pt1) (+ (cadr pt1) pd2)))
    (repeat (+ n2 1)
			          (MK-circle p12 10 7 "0")
                (setq p12(list (car p12) (+ (cadr p12) 75))))                     
(setq p13(list(car p6) (+ (cadr p6) pd2)))
	(repeat (+ n2 1)
		(MK-circle p13 10 7 "0")
		(setq p13(list (car p13) (+ (cadr p13) 75))))
(cond  ((= fd3 1)
	(progn 
		(setq p14 (list(+ (car p9)500)(cadr p9))
	    p15 (list(car p14) (cadr p7))
	    p16 (list (+ (car p15) (* s1 2)) (cadr p15))
	    p17 (list (car p16) (cadr pt0))
	    p18(list (+ (car p17) d3) (cadr p17))
	    p19(list (car p18) (cadr p14)))	
	(MK-line1 (list p16 p17 p18 p19))
	(entmake (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")'(100 . "AcDbPolyline") (cons 90 4); 顶点数               
  (cons 10 p19) (cons 10 p14) (cons 10 p15)(cons 10 p16)));顶点	
	(setq e2 (entlast))
	(command "fillet" "p" e2);倒左下圆角
	(MK-circle (list (+ (car p14) s1) (+ (cadr p14)s1)) 10 7 "0")(MK-circle (list (+ (car p15) s1) (- (cadr p15)s1)) 10 7 "0")
  (setq P20(list (+ (car p14) s1 pd1) (+ (cadr p14)s1 )))
	(repeat (+ n1 1)
                (entmake (list '(0 . "CIRCLE") (cons 10 p20) (cons 40  5)))
                (setq p20(polar p20 0 75)))  
 (setq P21(list (+ (car p14) s1 ) ( + (cadr p14) s1 pd2)))	
	(repeat (+ n2 1)
               (entmake (list '(0 . "CIRCLE") (cons 10 p21) (cons 40  5)))
             (setq p21(polar p21 (/ pi 2) 75)))	
(text (strcat (rtos fd1)"x" (rtos fd2)) (list (+ (car p14) (/ fd1 2)) (+ (cadr p14)s1))  40 1 1 "0")
(text "2" (list (+ (car p14) s1) (+ (cadr p14)s1))  30 4 1 "0")	
	))
((= fd3 2)
(progn 
	(setq p14 (list(+ (car p9)500)(cadr p9))
	      p15 (list(car p14) (cadr p7)) 
        p16 (list (+ (car p15) (* s1 2)) (cadr p15))
        p17 (list (+ (car p14)(* s1 2))	(cadr p14))	
)
	(MK-line1 (list p16 p17 ))
	(command "pline" p17 p14 p15 p16 "")
	(setq e2 (entlast))
	(command "fillet" "p" e2);倒左下圆角
(setq p18 (list (+ (car p16) 100 ) (cadr p16))
      p19 (list (+ (car p18) fd1) (cadr p18))
      p20 (list (car p19) (- (cadr p19)(* s1 2)))	
	    p21 (list (car p18)(cadr p20)))
	(MK-line (list p18 p19 p20 p21 ))
  (MK-circle (list (+ (car p14) s1) (+ (cadr p14)s1)) 10 7 "0")(MK-circle (list (+ (car p15) s1) (- (cadr p15)s1)) 10 7 "0")
(setq P22(list (+ (car p14) s1 ) ( + (cadr p14) s1 pd2)))	
	(repeat (+ n2 1)
               (entmake (list '(0 . "CIRCLE") (cons 10 p22) (cons 40  5)))
             (setq p22(polar p22 (/ pi 2) 75)))
(setq P23(list (+ (car p15) s1 100 pd1) (- (cadr p15)s1)))	
(repeat (+ n1 1)
               (entmake (list '(0 . "CIRCLE") (cons 10 p23) (cons 40  5)))
             (setq p23(polar p23 0 75)))
(text (strcat (rtos fd1)"x" (rtos fd2)"/1") (list (+ (car p18) (/ fd1 2)) (- (cadr p18)s1))  40 1 1 "0")
 (entmake (list '(0 . "TEXT") (cons 1 (strcat (rtos fd1)"x" (rtos fd2)"/2")) (cons 10 (list (+ (car p14) s1) (+ (cadr p14) (* 2 s1) (/ fd1 2)))) 
          (cons 11 (list (+ (car p14) s1) (+ (cadr p14) (* 2 s1) (/ fd1 2))))(cons 72  1) (cons 73 2)(cons 40 40) (cons 62 1)(cons 50 (/ pi 2))))
          ;0(类型） 1（内容） 10 11（插入点） 72 73（对齐方式*中心 73等于0为左) 40(字高)62（颜色）50（旋转角度）			
)))			
  (h-save1  '(fd1 fd2 fd3 ) "ffl")
    )))
    (setvar "osmode" 16383)  ;打开对象捕捉状态
    (command "._undo" "_end")
  )

;圆形软连接片法兰展开 RLJ
  (defun c:rlj(/ dcl_file dcl_id getdata1 make-dclcs pt0 re rld0 rld1 rld2 rld3 rld4 rld5 rld6 rld7 rld8 rld9 rlj)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "圆形软连接片法兰:dialog"
				 "{ // start dcl"
				 "label = \"圆形软连接片法兰\";"	
         ":row{"
         ":boxed_column{label = \"交互参数\";"			 
				 ":edit_box{label=\"法兰内径:\";key=\"d0\";}";编辑框
				 ":edit_box{label=\"法兰中径:\";key=\"d1\";}";编辑框
				 ":edit_box{label=\"法兰外径:\";key=\"d2\";}";编辑框
				 ":edit_box{label=\"法兰开孔:\";key=\"d3\";}";编辑框
				 ":edit_box{label=\"开孔数量:\";key=\"d4\";}}";编辑框
				 ":boxed_column{label = \"设置参数\";"
				 ":edit_box{label=\"铆钉间距:\";key=\"d5\";}"
				 ":edit_box{label=\"立边高度:\";key=\"d6\";}"
				 ":edit_box{label=\"立边厚度:\";key=\"d7\";}"
				 ":edit_box{label=\"压条高度:\";key=\"d8\";}"
				 ":edit_box{label=\"压条厚度:\";key=\"d9\";}}}"         
				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun rlj (pt0 / d0 d1 d2 d3 d4 d5 d6 duration e0 e1 e2 end p1 p11 p12 p13 p14 p2 p3 p4 p5 p6 p7 p8 p9 pt1 pt2 pt3 start)
		
		(command "._undo" "_begin")
		(setvar "cmdecho" 0) ;关闭普通命令提示信息
		(setvar "osmode"  0)  ;关闭对象捕捉状态
  	(setq start (getvar "MILLISECS"))		
		
  (setq d0 (+ rld0 (* rld7 2)));圆的内径=片法兰内径+立边厚度*2
  ;以上为参数获取
	(MK-circle pt0 rld0 1 "3中心线层");绘制圆的原始内径	
	(MK-circle pt0 d0 7 "0");绘制圆的内径
	(setq e0 (entlast))
  (MK-circle pt0 rld1 1 "3中心线层");绘制圆的中径
	(setq e1 (entlast))	
	(MK-circle pt0 rld2 7 "0");绘制圆的外径
  (setq e2 (entlast))		
  (ddi (polar pt0 pi (/ d0 2)) (polar pt0 0 (/ d0 2)) (polar pt0 0 (/ d0 2)));标注圆的内径		
  (ddi (polar pt0 (ang 195) (/ rld1 2)) (polar pt0 (ang 15) (/ rld1 2)) (polar pt0 (ang 15) (/ rld1 2)));标注圆的中径	
  (ddi (polar pt0 (ang 210) (/ rld2 2)) (polar pt0 (ang 30) (/ rld2 2)) (polar pt0 (ang 30) (/ rld2 1.5)));标注圆的外径			
  (MK-circle1 (cdr (MK-Curve-getDIVPoints e1 rld4 1)) 10 7 "0");绘制螺栓开孔	
	(if (>= rld0 160)
		(progn (if(<= rld0 500)(setq d1 3) (setq d1 4));判断分段
		(MK-CircleDivideLines	e0 e2 (/ 180.0 rld4) d1)));绘制等分线			
	(text (strcat "%%c"(rtos rld0 2 2)"/1") (polar pt0 (ang 45) (/ rld1 2)) 50 1 1 "0")
	(text (strcat (rtos d1 2 2)) (polar pt0 (ang 60) (/ rld1 2)) 50 4 1 "0")	
	(text (strcat "法兰内径为(片法兰加立边)"  (rtos d0 2 2)) (AA PT0 0 (* RLD2 -1)) 100 7 1 "序号图层")
  (text (strcat "法兰中心距为"  (rtos rld1 2 2))  (AA PT0 0 (* (+ RLD2 150) -1))   100 7 1 "序号图层")
	(text (strcat "法兰外径为"  (rtos rld2 2 2))  (AA PT0 0 (* (+ RLD2 300) -1))   100 7 1 "序号图层")
	(text (strcat "开孔大小为"  (rtos rld3 2 2))  (AA PT0 0 (* (+ RLD2 450) -1))   100 7 1 "序号图层")
	(text (strcat "开孔数量为"  (rtos rld4 2 2))  (AA PT0 0 (* (+ RLD2 600) -1))   100 7 1 "序号图层")
	(text (strcat "%%c"(rtos rld0 2 2) "片法兰" )  (AA PT0 0 (* (+ RLD2 2000) -1))   300 1 1 "序号图层")
		
	(setq pt1(AA PT0  (+ RLD2 1500) 0 );寻得立边第一点位
	      p1 (AA pt1 0 rld6);获取立边高度，第二点位
		    p2 (AA p1 (- (* pi (+ rld0 rld7)) 1) 0);圆周长展开，第三点位
		    p3 (AB p2 pt0 0 0));第四点位
	(MK-line (list pt1 p1 p2 p3));绘制立边
  (dim pt1 p1 2 -30) (dim p1 p2 1 30);标注立边
(setq p4 (AA pt1 10 (- rld6 (/ rld8 2)));标注第一个铆钉开孔定位点	
	    p5 (AA p3  -10 (- rld6 (/ rld8 2))));标注最后一个铆钉开孔定位点	
(MK-circle1 (MK-SplitPoints p4 p5 rld5) 4.2 7 "0");绘制铆钉孔	
(text (strcat "%%c"(rtos rld0 2 2)"/2") (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) (/ rld6 2)) 50 1 1 "0")	
(text (strcat "立边高度为"  (rtos rld6 2 2))  (AA (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) 0) 0 (* RLD2 -1))   100 7 1 "序号图层")
(text (strcat "立边厚度为"  (rtos rld7 2 2))  (AA (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) 0) 0 (* (+ RLD2 150) -1))   100 7 1 "序号图层")
(text (strcat "铆钉间距为"  (rtos rld5 2 2))  (AA (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) 0) 0 (* (+ RLD2 300) -1))   100 7 1 "序号图层")
(text (strcat "计算展开为" (rtos (+ rld0 rld7) 2 2) "*π- 1")  (AA (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) 0) 0 (* (+ RLD2 450) -1))   100 7 1 "序号图层")			
(text (strcat "%%c"(rtos rld0 2 2) "立边" )  (AA (AA pt1 (/ (- (* pi (+ rld0 rld7)) 1) 2) 0) 0 (* (+ RLD2 2000) -1))   300 1 1 "序号图层")	
(setq pt2 (AB p3 pt1 1500 0  );寻得压条第一点
	    d2  (-(* pi (+ rld0 (* rld7 2) 3 rld9)) 3);d2为压条的展开周长
	    p6  (AA pt2 0 rld8)	
	    p7  (AA p6 d2 0)
	    p8  (AB p7 PT2 0 0))
(MK-line (list pt2 p6 p7 p8));绘制压条
(dim pt2 p6 2 -30) (dim p6 p7 1 30);标注压条		
(setq p9 (AA pt2 10 (/ rld8 2));标注第一个铆钉开孔定位点	
	    )
		 
(setq d3(ang (/ (* 180 rld5) (* (/ (+ rld0  rld7) 2) pi)));计算螺栓孔距在立边中心的长度
      d4(ang(/ (* 180 20) (* (/ (+ rld0  rld7) 2) pi))))	
(setq d5(* (/ (+ rld0  (* rld7 2) 3 rld9) 2) d3)
      d6(- (* (/ (+ rld0  (* rld7 2) 3 rld9) 2) d4) 10)
	    p11(list(- (+ (car pt2) d2 1.5) d6 )(+ (cadr pt2) (/ rld8 2))));标注最后一个铆钉开孔定位点		
(mapcar (function (lambda (x) (yxk2 x 6 4.5)))
  (MK-SplitPoints p9 p11 d5))	
	(text (strcat "%%c"(rtos rld0 2 2)"/3") (AA pt2 (/ d2 2) (/ rld8 2)) 50 1 1 "0")	
	(text (strcat "压条高度为"  (rtos rld8 2 2))  (AA (AA pt2 (/ d2 2) 0) 0 (* RLD2 -1))   100 7 1 "序号图层")
  (text (strcat "压条厚度为"  (rtos rld9 2 2))  (AA (AA pt2 (/ d2 2) 0) 0 (* (+ RLD2 150) -1))   100 7 1 "序号图层")
	(text (strcat "铆钉间距为"  (rtos d5 2 2)"  (此为模拟计算与立边孔重合数据)")  (AA (AA pt2 (/ d2 2) 0) 0 (* (+ RLD2 300) -1))   100 7 1 "序号图层")
	(text (strcat "计算展开为"  (rtos (+ rld0 (* rld7 2) 3 rld9) 2 2) "*π- 3")   (AA (AA pt2 (/ d2 2) 0) 0 (* (+ RLD2 450) -1))   100 7 1 "序号图层")	
  (text (strcat "%%c"(rtos rld0 2 2) "压条" )  (AA (AA pt2 (/ d2 2) 0) 0 (* (+ RLD2 2000) -1))   300 1 1 "序号图层")		
	(setq pt3 (AA PT0 -1500 1000)
		    P12 (AA (AA (AA pt2 (/ d2 2) 0) 0 (* (+ RLD2 2000) -1)) 2000 -500)
		    P13 (LIST(car pt3) (cadr p12))
		    p14 (list (car p12) (cadr pt3)))
	(MK-mline (list pt3 p13 p12 p14) 1)
 	(setq end (getvar "MILLISECS"))
	(setq duration  (- end start) )		
	(text (strcat "%%c"(rtos rld0 2 2) "圆形软连接片法兰+立边,程序生成时间" (rtos duration 2 2 )  "毫秒") (AA PT3 0 30 )     200 1 0 "序号图层")
		(setvar "osmode" 16383)  ;打开对象捕捉状态
		(command "._undo" "_end")	
		
	)
	;;---------开始写面板调用函数
	(if (not rld0)
		(progn (setq rld0 501)
			
      (setq rld1 540)(setq rld2 580)(setq rld3 10)(setq rld4 8)
			(setq rld5 100)(setq rld6 50)
			(setq rld7 5)(setq rld8 35)(setq rld9 1)
		))
	
	(h-read1  "rlj");读取注册表的数据
	(defun getdata1()
		(setq 
			rld0 (atof (get_tile "d0"))
			rld1 (atof (get_tile "d1"))
			rld2 (atof (get_tile "d2"))
			rld3 (atof (get_tile "d3"))
			rld4 (atoi (get_tile "d4"))
			rld5 (atof (get_tile "d5"))
			rld6 (atof (get_tile "d6"))
			rld7 (atof (get_tile "d7"))
			rld8 (atof (get_tile "d8"))
			rld9 (atof (get_tile "d9"))
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "圆形软连接片法兰" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
   (set_tile "d0" (rtos rld0 2 2) );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos rld1 2 2));
  (set_tile "d2" (rtos rld2 2 2))
  (set_tile "d3" (rtos rld3 2 2));
	(set_tile "d4" (rtos rld4 2 2))
	(set_tile "d5" (rtos rld5 2 2 ))
	(set_tile "d6" (rtos rld6 2 2 ))
  (set_tile "d7" (rtos rld7 2 2 ))
  (set_tile "d8" (rtos rld8 2 2 ))
	(set_tile "d9" (rtos rld9 2 2 ))
	
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "这里填充说明")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				
				(setq pt0 (getpoint "请选择图形插入点"))

				(rlj pt0)
			
			))	
	)	
	
	(h-save1  '(rld0 rld1 rld2 rld3 rld4 rld5 rld6  rld rll rld7 rld8 rld9) "rlj");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;贴边马口展开 C3A
(defun c:c3a(/ d1 d2 pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11  ) ;贴边马口开料
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
   (command "._undo" "_begin")
(setq d1(getreal "开口贴边长<597>"))
(if (not d1) (setq d1 597))
(setq d2(getreal "开口贴边宽<597>"))
(if (not d2) (setq d2 597))
(setq pt0(getpoint "插入点"))
;上面的为需要的固定参数
;编程开始
(setq p1(list (car pt0) (+ (cadr pt0) d2))
      p2(list (+ (car p1) 0.2) (+ (cadr p1) 0.0))
      p3(list (car p2) (- (cadr p2) 0.5))
      p4(list (+ (car p3) (- d1 0.4)) (cadr p3))
      p5(list (car p4) (+ (cadr p4) 0.5))
      p6(list (+ (car p5) 0.2) (cadr p5))
      p7(list (car p6) (cadr pt0))
      p8(list (- (car p7) 0.2) (cadr p7))
      p9(list (car p8) (+ (cadr p8) 0.5))
      p10(list (car p3) (cadr p9))
      p11(list (car p10) (- (cadr p10) 0.5)))
(command "line" pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 "c")
  
  
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;德国项目支架 C3B
(defun c:c3b(/ d4 d5 make_dgzj_dcl p1 p10 p11 p1a p2 p2a p3 p3a p4 p4a p5 p5a p6 p6a p7 p8 p9 pt0) ;德国支架绘制
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
	(defun make_DGZJ_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "德国项目支架:dialog { //定义名字为德国项目支架的对话框"
 "     label= \"德国项目支架\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"序号          (个)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d0\";//编辑框1的关键字"
  "               mnemonic = \"d0\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"支架数量      (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"支架长        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"保温厚度     (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-DGZJ.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
   (command "._undo" "_begin")
  (setq Keys '("d0" "d1" "d2" "d3"))
  (if (not c3bd0)
  (progn
  (setq c3bd0 1 c3bd1 2)
  (setq c3bd2 600 c3bd3 80);设变量初值
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_DGZJ_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "德国项目支架" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list (rtos c3bd0 2 2)
                   (rtos c3bd1 2 2)  (rtos c3bd2 2 2)
		   (rtos c3bd3 2 2) 

		   )
    )
    ;设置d1为焦点
    (mode_tile "d0" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c3b\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
 (setq pt0(getpoint"请点击插入的位置:"))
  (if (= c3bd3 80)
    (progn
    (setq d4 53)
    (setq d5 28))
    
    (progn
    (if (= c3bd3 100)
      (progn
     (setq d5 28)
    (setq d4 73))
      (progn
     (setq d5 13)
     (setq d4 23)))))

(setq p1(list (car pt0) (+ (cadr pt0) d4))
      p2(list (car p1) (+ (cadr p1) 196))
      p3(list (car p2) (+ (cadr p2) d4))
      p4(list (+ (car p3) c3bd2 90) (cadr p3))
      p5(list (car p4) (cadr p2))
      p6(list (+ (car p5) d5) (cadr p5))
      p7(list (car p6) (cadr p1))
      p8(list (car p5) (cadr p1))
      p9(list (car p4) (cadr pt0)))
 (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
 (cons 90 4) (cons 10 p8) (cons 10 p9)(cons 10 pt0)(cons 10 p1)))
   (command "fillet" "r" 3)
   (command "fillet" "p" (entlast));倒R5圆角		   
	   
 (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
 (cons 90 4) (cons 10 p2) (cons 10 p3)(cons 10 p4)(cons 10 p5)))
   (command "fillet" "r" 3)
   (command "fillet" "p" (entlast));倒R5圆角		   	   
	   
  (command "line" p1 p2  "")
  (command "line" p5 p6 p7 p8  "")	   

	   
  (setq p1a(list (+ (car p1) 1) ( cadr p1))
      p2a(list (+ (car p2) 1) ( cadr p2))
      p3a(list (- (car p5) 1) ( cadr p5))
      p4a(list (car p5) (- ( cadr p5) 1))
      p5a(list (- (car p8) 1) ( cadr p8))
      p6a(list (car p8) (+ ( cadr p8) 1)))
  (command "color" 2)
  (command "line" p1 p1a "")
  (command "line" p2 p2a "")
  (command "line" p5 p3a "")
  (command "line" p5 p4a "")
  (command "line" p8 p5a "")
  (command "line" p8 p6a "")
  (command "color" 7)
  (command "-DIMSTYLE" "R" "m-5")
  (setvar "dimtix" 1) ;强制尺寸文本在两尺寸界线之内
  (command "dimlinear" pt0 p1 "@-50,50")
  (command "dimlinear" p1 p2 "@-50,50")
  (command "dimlinear" p2 p3 "@-50,50")
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimlinear" p3 p4 "@-100,100")
  (setq p10(list (+ (car p3) (/ (+ c3bd2 90) 2)) (+ (cadr p1) 98)))
  (setq p11(list (+ (car p10) 250) (cadr p10)))
  (command "color" 1)
  (setq c3bd0s(rtos c3bd0 2 2))
  (command "text" "m" p10 200 0  c3bd0s)
  (command "color" 4)
  (if (/= c3bd1 1)
  (command "text" "m" p11 100 0  c3bd1))
  (command "color" 7)
  (command "color" "red")
  (command "layer" "S" "3中心线层" "")
  (command "line" p2 p5 "")(command "line" p1 p8 "");绘制中心线
    (command "color" "byblock")
  (command "layer" "S" "1轮廓层" "")))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;厂标圆法兰 YFL
(defun c:yfl(/ d1 d2 d3 d4 d5 e1 e2 pt0 pt1);圆法兰下料
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
  
  (setq d1(getreal "\n 风管外径<150>:"));风管外径和法兰内径
  (if (not d1) (setq d1 150))
  (SETQ d2(+ d1 1))
  (SETQ pt0(getpoint "\n 插入点："))
  (if
    (< d1 1000)
    (progn
      (setq d3(+ d2 40) d4(+ d2 80)))
    (progn
      (setq d3(+ d2 50) d4(+ d2 100)))
    );中心孔径和法兰外径
  (MK-circle pt0 d2 7 "0")
	(MK-circle pt0 d3 7 "0")
  (setq e1(entlast))
	(MK-circle pt0 d4 7 "0")	 
  (setq pt1(list (car pt0) (+ (cadr pt0) (/ d3 2))))
	(MK-circle pt1 10 7 "0")
  (setq e2(entlast))
(if
  (< d1 300)
  (progn
    (setq d5 8);螺栓孔数
    )
  (progn
    (if
      (< d1 350)
      (setq d5 16)
      (progn
	(if(< d1 450)
      (setq d5 20)
      (progn
	(if(< d1 550)
      (setq d5 24)
      (progn
	(if(< d1 650)
      (setq d5 28)
      (progn
	(if(< d1 750)
      (setq d5 32)
      (progn
	(if(< d1 850)
      (setq d5 36)
      (progn
	(if(< d1 950)
      (setq d5 40)	  
      (progn
	(if(< d1 1000)
      (setq d5 44)
      (progn
	(if(< d1 1100)
      (setq d5 48)
      (progn
	(if(< d1 1200)
      (setq d5 52)
      (progn
	(if(< d1 1300)
      (setq d5 56)
      (progn
	(if(< d1 1400)
      (setq d5 60)
      (progn
	(if(< d1 1500)
      (setq d5 64)
      (progn
	(if(< d1 1600)
      (setq d5 68))))))))))))))))))))))))))))))	  
  (command "array" e2 "" "po" pt0 d5 "" "" "")
  (command "erase" e1 "")
    (setvar "osmode" 16383)  ;打开对象捕捉状态  
  (command "._undo" "_end")
	(princ) ;静默退出
  )

;底平侧平变径三通 C7D
(defun c:c7d(/ d13a d14a d16 d17 d18 d19 d20 d21 make_dpzb4_dcl p1 p10 p10a p11 p11a p12 p12a p13 p13a p14 p14a p15 p15a p16 p16a p17 p17a p18 p18a p19 p19a p1a p2 p20 p20a p21 p21a p22 p22a p23 p24 p25 p26 p27 p28 p29 p2a p3 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 p3a p4 p40 p41 p42 p43 p44 p45 p46 p47 p48 p49 p4a p5 p50 p51 p52 p53 p54 p55 p56 p5a p6 p6a p7 p7a p8 p8a p9 p9a pt0);变径马口三通
   (command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
(defun make_DPZB4_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "底平变径三通:dialog { //定义名字为底平变径三通的对话框"
 "     label= \"底平变径三通\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"主管A面（带变径）(个)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "               mnemonic = \"d1\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"主管B面（支架面）(mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口长           (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口宽           (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d4\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口距X边        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d5\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"马口距Y边        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d6\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 	 	 
  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径宽           (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d7\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"
	 
	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径深           (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d8\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径宽偏移       (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d9\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

	 
	   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"变径深偏移       (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d10\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"



             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-DPZB4.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
  (setq Keys '("d1" "d2" "d3" "d4" "d5" "d6" "d7" "d8" "d9" "d10"))
  (if (not c7dd1)
  (progn
  (setq c7dd1 597)
  (setq c7dd2 597)
  (SETQ c7dd3 397 c7dd4 497);设变量初值
  (SETQ c7dd5 200)
  (setq c7dd6 50 c7dd7 547)
  (setq c7dd8 497 c7dd9 0)
  (setq c7dd10 0)))
  
    ;加载DCL对话框
    (setq DcLwjm (make_DPZB4_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "底平变径三通" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list
                   (rtos c7dd1 2 2)  (rtos c7dd2 2 2)
		   (rtos c7dd3 2 2)  (rtos c7dd4 2 2)
		   (rtos c7dd5 2 2)  (rtos c7dd6 2 2)
		   (rtos c7dd7 2 2)  (rtos c7dd8 2 2)
		   (rtos c7dd9 2 2)  (rtos c7dd10 2 2)
		   )
    )
    ;设置d1为焦点
    (mode_tile "d1" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c7d\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
   (setq c7cd2 1928.5)(SETQ c7cd5 198.5)(SETQ c7cd6 150)(SETQ c7cd7 48.5)
  (setq pt0(getpoint"请点击插入的位置:"))
  (setq d16(sqrt(+ (* (abs (+ (- c7dd7 c7dd1) c7dd9)) (abs (+ (- c7dd7 c7dd1) c7dd9))) (* 300 300))));前嵌板(实际为左嵌板斜边长)
  (setq d17(sqrt(+ (* c7dd9 c7dd9) (* 300 300))));后嵌板(实际为右嵌板斜边长）
  (setq d18(sqrt(+ (* c7dd10 c7dd10) (* 300 300))));左嵌板(实际为后嵌板斜边长）
  (setq d19(sqrt(+ (* (abs (+ (- c7dd8 c7dd2) c7dd10)) (abs (+ (- c7dd8 c7dd2) c7dd10))) (* 300 300))));右嵌板(实际为前嵌板斜边长)
  (setq d13a(- c7dd1 c7dd9 c7dd7));宽偏移变量
  (setq d14a(- c7dd2 c7dd10 c7dd8));深偏移变量
  (setq d21(sqrt(+ (* c7cd6 c7cd6) (* (- c7cd5 c7cd7) (- c7cd5 c7cd7)))))
   ;上列为获取数据
(SETQ P1(LIST (CAR PT0) (+ (cadr pt0) (- c7dd2 148.5)))
      P2(LIST (car P1) (+ (cadr p1) c7dd1))
      p3(list (car P2) (+ (cadr p2) c7dd2))
      p4(list (car P3) (+ (cadr p3) c7dd1))
      p5(list (car P4) (+ (cadr p4) 148.5))
      p6(list (+ (car P5) c7cd2) (cadr p5))
      p7(list (car P6) (cadr p4))
      p8(list (+ (car p7) d19) (- (cadr p7) d13a));带出变径前嵌板,d19为前嵌板斜边长
      p9(list (+ (car p8) 48.5) (cadr p8));此48.5后续可以变更为变量，根据需要变更
      p10(list (car p9) (- (cadr p9) c7dd7))
      p11(list (- (car p10) 48.5) (cadr p10));此48.5后续可以变更为变量，根据需要变更
      p12(list (car p7) (cadr p3))
      p13(list (car p12) (cadr p2))
      p14(list (+ (car p13) d18) (- (cadr p13) c7dd9));带出变径后嵌板(短边)，d18为前嵌板斜边长
      p15(list (+ (car p14) 48.5) (cadr p14));此48.5后续可以变更为变量，根据需要变更
      p16(list (car p15) (- (cadr p15) c7dd7))
      p17(list (car p14) (cadr p16))
      p18(list (car p13) (cadr p1))
      p19(list (car p13) (cadr pt0)))
  (command "line" pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 "c")
  
  (setq p1a(list (+ (car p1) 1) (cadr p1))
	p2a(list (+ (car p2) 1) (cadr p2))
	p3a(list (+ (car p3) 1) (cadr p3))
	p4a(list (+ (car p4) 1) (cadr p4))
	p5a(list (- (car p7) 1) (cadr p7))
	p6a(list (car p8) (- (cadr p8) 1))
	p7a(list (car p11) (+ (cadr p11) 1))
	p8a(list (- (car p12) 1) (cadr p12))
	p9a(list (- (car p13) 1) (cadr p13))
	p10a(list (car p14) (- (cadr p14) 1))
	p11a(list (car p17) (+ (cadr p17) 1))
	p12a(list (- (car p18) 1) (cadr p18)))
  (command "color" "yellow")
  (command "line" p1 p1a "")(command "line" p2 p2a "")
  (command "line" p3 p3a "")(command "line" p4 p4a "")
  (command "line" p7 p5a "")(command "line" p8 p6a "")		 
  (command "line" p11 p7a "")(command "line" p12 p8a "")
  (command "line" p13 p9a "")(command "line" p14 p10a "")
  (command "line" p17 p11a "")(command "line" p18 p12a "")
  (command "color" "red")
  (command "layer" "S" "3中心线层" "")
  (command "line" p1 p18 "")(command "line" p2 p13 "")
  (command "line" p3 p12 "")(command "line" p4 p7 "")
  (command "color" "byblock")
  (command "layer" "S" "0" "")
  (command "-DIMSTYLE" "R" "m-10")
  (setvar "dimtix" 1) ;强制尺寸文本在两尺寸界线之内
  (command "dimlinear" pt0 p1 "@-50,50")
  (command "dimlinear" p1 p2 "@-50,50")
  (command "dimlinear" p2 p3 "@-50,50")
  (command "dimlinear" p3 p4 "@-50,50")
  (command "dimlinear" p4 p5 "@-50,50")
  (command "dimlinear" p7 p8 "v" "@150,-150")
  (command "dimlinear" p11 p10 "@-50,-150")
  (command "dimlinear" p11 p12 "@150,-250")
  (command "dimlinear" p13 p14 "v" "@-100,100")
  (command "dimlinear" p17 p18 "@250,-100")
  (command "dimlinear" p9 p10 "@150,-150")
  (command "dimlinear" p15 p16 "@150,-150")
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimlinear" pt0 p5 "@-250,-250")
  (command "dimlinear" p5 p6 "@-250,150")
  (setq p29 (list (+ (car p19) 700) (cadr p19));变径贴边料基准点(右嵌板斜边长)
        p30 (list (+ (car p29) d14a) (+ (cadr p29) d17))
        p31 (list (car p30) (+ (cadr p30) 48.5))
	p32 (list (+ (car p31) c7dd8) (cadr p31))
	p33 (list (car p32) (cadr p30))
	p34 (list (+ (car p29) c7dd2) (cadr p29)))
  (setq p35 (list (+ (car p34) 500) (cadr p34));变径贴边料基准点2(左嵌板斜边长）
	p36 (list (+ (car p35) c7dd10) (+ (cadr p35) d16))
	p37 (list (car p36) (+ (cadr p36) 48.5))
	p38 (list (+ (car p37) c7dd8) (cadr p37))
	p39 (list (car p38) (cadr p36))
	p40 (list (+ (car p35) c7dd2) (cadr p35)))
  (command "line" p29 p30 p31 p32 p33 p34 "c")(command "line" p35 p36 p37 p38 p39 p40 "c")
  (setq p13a(list (+ (car p30) 1) (cadr p30))
	p14a(list (- (car p33) 1) (cadr p33))
	p15a(list (+ (car p36) 1) (cadr p36))
	p16a(list (- (car p39) 1) (cadr p39)))
  (command "color" "yellow")
  (command "line" p30 p13a "") (command "line" p33 p14a "") (command "line" p36 p15a "")
  (command "line" p39 p16a "")
  (command "color" 7)
  (command "-DIMSTYLE" "R" "m-8")
  (command "dimlinear" p29 p31 "v" "@-150,-100")
  (command "dimlinear" p31 p32 "h" "@-150,50")
  (command "dimlinear" p32 p33 "v" "@50,-50")
  (command "dimlinear" p29 p34 "h" "@-150,-150")
  (command "dimlinear" p35 p36 "h" "@-100,-150")
  (command "dimlinear" p39 p40 "h" "@-50,150")
  (command "dimlinear" p35 p37 "v" "@-150,-150")
     (setq d20(- c7dd1 c7dd4));假设贴下边，此时上开口距离上边的距离
     (setq p20(list (+ (car p1) (- c7cd2 c7dd5 c7dd3 c7cd6 3)) (+ (cadr p1) (- c7dd1 c7dd6 c7dd4)));定位开口右下点
           p21(list (+ (car p20) c7dd3 c7cd6 3) (cadr p20))
	   p22(list (car p21) (+ (cadr p21) c7dd4 3))
	   p23(list (car p20) (cadr p22)))
     ;下面为假设条件
     (if (= c7dd6 0);1、假设口径贴在上面
       (progn
	 (setq p24(list (- (car p22) 0.2) (cadr p22))
	       p25(list (car p24) (- (cadr p24) 0.5))
	       p26(list (+ (car p23) 0.2) (cadr p25))
	       p27(list (car p26) (cadr p24)))
	       (command "line"  p20 p21 p22 p24 p25 p26 p27  p23 "c")
	 ))
     (if (= c7dd6 d20);2、假设口径贴在下面
       (progn
	 (setq p24(list (- (car p21) 0.2) (cadr p21))
	       p25(list (car p24) (+ (cadr p24) 0.5))
	       p26(list (+ (car p20) 0.2) (cadr p25))
	       p27(list (car p26) (cadr p20))
	       )
	       (command "line" p20 p27 p26 p25 p24 p21 p22 p23 "c")
	 ))
     (if (/= c7dd6 0);3、假设开口不贴边
       (progn
	 (if (/= c7dd6 d20)
	   (progn
	 (command "line" p20 p21 p22 p23 "c")))))
	 	 (setq p41(list (+ (car p31) 1200) (+ (cadr p31) 600))
	       p42(list (car p41) (+ (cadr p41) c7cd5))
	       p43(list (+ (car p42) c7dd4)(cadr p42))
	       p44(list (+ (car p43) c7dd3)(cadr p43))
	       p45(list (car p44) (- (cadr p44) c7cd7))
	       p46(list (+ (car p45) c7cd6) (cadr p41))
	       p47(list (car p43) (cadr p41))
	       p54(list (- (car p42) c7dd3) (cadr p42))
	       p55(list (car p54) (cadr p45))
	       p56(list (- (car p55) c7cd6) (cadr p41)))	 
	 (command "line" p56 p55 p54 p42 p43 p44 p45 p46 p47 p41 "C")
	 (setq p48(list (+ (car p46) 300) (cadr p46))
	       p49(list (car p48) (+ (cadr p48) d21))
	       p50(list (car p49) (+ (cadr p49) c7cd7))
	       p51(list (+ (car p50) c7dd4) (cadr p50))
	       p52(list (car p51) (cadr p49))
	       p53(list (car p52) (cadr p48)))
       (command "line" p48 p49 p50 p51 p52 p53 "c")
(setq p17a(list (car p43) (- (cadr p43) 1))
      p18a(list (car p47) (+ (cadr p47) 1))
      p19a(list (+ (car p49) 1) (cadr p49))
      p20a(list (- (car p52) 1) (cadr p52))
      p21a(list (car p42) (- (cadr p42) 1))
      p22a(list (car p41) (+ (cadr p41) 1)))
(command "color" 2)
(command "line" p17a p43 "")(command "line" p18a p47 "")
(command "line" p19a p49 "")(command "line" p20a p52 "")
(command "line" p21a p42 "")(command "line" p22a p41 "")
(command "color" 7)
(command "dimlinear" p41 p42 "v" "@-100,-150")
(command "dimlinear" p42 p43 "h" "@-100,100")
(command "dimlinear" p43 p44 "h" "@-100,100")
(command "dimlinear" p42 p54 "h" "@-100,100")
(command "dimlinear" p44 p45 "v" "@150,100")
(command "dimlinear" p48 p49 "v" "@-150,-100")
(command "dimlinear" p50 p51 "h" "@-100,100")
))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
  (princ) ;静默退出
  )

;自动编号 SS 
(defun c:ss(/  d2s dcl_file dcl_id getdata1 make-dclcs pt0 re)
	(defun make-dclCS  (/ lst_str str file f);;面板的界面显示dcl
		(setq lst_str
			'(
				 "自动编号:dialog"
				 "{ // start dcl"
				 "label = \"自动编号\";"
				 ":column{"
				 ":row{:edit_box{label=\"编号前缀为：\";key=\"d1\"; edit_width=10;}}"
				 ":row{:edit_box{label=\"起始数字为：\";key=\"d2\"; edit_width=10;}}"
				 ":row{:edit_box{label=\"编号大小为：\";key=\"d3\"; edit_width=10;}}"
				 "}"
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\";
				 is_default=true;height=2;}"	":button{label=\"取消(&C)\";key=\"cancel\";is_cancel=true;height=2;}""}"
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 )
		)
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(h-read1 "ss")
	;;---------开始写面板调用函数
  (if (/= 'str (type bhd1)) (setq bhd1 "1/")) ;判断变量是否存在并且为字符串，如果不是则进行初始化定义
   (setq bhd2 "1");判断变量是否存在并且为字符串，如果不是则进行初始化定义
  (if (/= 'str (type bhd3)) (setq bhd3 "150"));判断变量是否存在并且为字符串，如果不是则进行初始化定义
  (defun getdata1() ;获取当前dcl界面里面控件key的当前值,并保存为全局变量，这里需要保存值的变量名字（JH bhd2 JR）尽量起的复杂一点，否则会引起全局变量冲突
    (setq bhd1  (get_tile "d1"))
    (setq bhd2  (get_tile "d2"))
    (setq bhd3  (get_tile "d3"))
	)
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "自动编号" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
      ;设置d1为焦点
    
  (set_tile "d1" bhd1) ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d2" bhd2);将对应key的全局变量传递给控件
  (set_tile "d3" bhd3);将对应key的全局变量传递给控件
  (mode_tile "d1" 2)
  (action_tile "accept" "(getdata1)(done_dialog 1)") ;当按下确认按钮的时候保存控件值，然后退出界面,并执行对于功能函数
  (action_tile "cancel" "(getdata1)(done_dialog 0)") ;当按下取消按钮的时候保存控件值，然后退出界面
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (if (= re 1) ;鼠标按下确认后，开始执行这里的操作
		(progn
			(h-save1 '(bhd1 bhd3) "ss")
      (while (< (atof bhd2) 9999)
				(progn	
					(setq pt0 (getpoint "\n请选择插入点: "))	
		      (if (null pt0) 
					(VL-EXIT-WITH-ERROR "");退出程序函数	；比EXIT和QUIT好.
					)		
					
					(setq d2s bhd2)
					;(command "color" 1)
					(text (strcat bhd1  d2s) pt0  (atoi bhd3)  1 1 "0")
					;(command "text" "m" pt0 bhd3 0 (strcat bhd1  d2s))
					(setq bhd2 (itoa(1+ (atoi bhd2))))
					)) ;鼠标按下确认后，将各个控件的值汇总到这里，传递给功能函数，执行功能操作		
		)
	)
	(princ)
)

;自动改变编号 CHN
(defun c:chn (/ cr in ll obj qz sn sortx- sortx+ sorty- sorty+ ss tw zt)
  (setq ss (ssget '((0 . "TEXT,MTEXT"))))
  (setq ll (acet-ss-to-list ss))
	(defun sortx+ (lst)
  (setq lst (vl-sort lst '(lambda (p1 p2)(< (car (cdr (assoc 10 (entget p1))))
                              (car (cdr (assoc 10 (entget p2))))))))
)
(defun sortx- (lst)
  (setq lst (vl-sort lst '(lambda (p1 p2)(> (car (cdr (assoc 10 (entget p1))))
                              (car (cdr (assoc 10 (entget p2))))))))
)
(defun sorty+ (lst)
  (setq lst (vl-sort lst '(lambda (p1 p2)(< (cadr (cdr (assoc 10 (entget p1))))
                              (cadr (cdr (assoc 10 (entget p2))))))))
)
(defun sorty- (lst)
  (setq lst (vl-sort lst '(lambda (p1 p2)(> (cadr (cdr (assoc 10 (entget p1))))
                              (cadr (cdr (assoc 10 (entget p2))))))))
)
  (initget "LD LU RD RU DL DR UL UR")
  (if tw nil (setq tw "DL"))
  (cond
    ((or (= tw "DL")(= tw "DR"))     
      (setq ll (sorty+ ll))
      (if (= tw "DL")(setq ll (sortx+ ll))(setq ll (sortx- ll)) )
    )
    ((or (= tw "LD")(= tw "LU"))     
      (setq ll (sortx+ ll))
      (if (= tw "LD")(setq ll (sorty+ ll))(setq ll (sorty- ll)) )
    )
    ((or (= tw "RD")(= tw "RU"))     
      (setq ll (sortx- ll))
      (if (= tw "RD")(setq ll (sorty+ ll))(setq ll (sorty- ll)) )
    )   
   ((or (= tw "UL")(= tw "UR"))     
      (setq ll (sorty- ll))
      (if (= tw "UL")(setq ll (sortx+ ll))(setq ll (sortx- ll)) )
    )
  )
  (setq qz (getstring "\n请输入前缀相同的部分: "))
  (setq sn (getint "\n输入开始编号 <1>:"))
  (if sn nil (setq sn 1))
  (if in nil (setq in 1))
  (if cr nil (setq cr 1))
  (setq zt "宋体")
  (foreach i ll
    (setq obj (vlax-ename->vla-object i))
    (vla-put-textstring obj (strcat qz (itoa sn)))
    (vla-put-stylename obj zt)
;设置字体
    (vla-put-color obj cr)
;设置字体颜色，1：红色  2：黄色  3：绿色  5：蓝 7：白   
    (setq sn (+ sn in))
  )
)

;自动生成尾料 FW
(defun c:fw ()
(setvar "SECURELOAD" 0)
(setvar "cmdecho" 0)
(setq url "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/EXP.dll")
	         
(setq dir (strcat (getvar "ROAMABLEROOTPREFIX") "Support\\EXP.dll"))
(if (findfile dir)
	  (command "NETLOAD" dir)
	  (progn
		(DownLoad url dir)
	 (command "NETLOAD" dir)
		))
	(princ)
	(command "FindWaste")
 (princ)
)

;自动创建领料单 DTE
(defun c:dte (/ dir filepath templatedir url1 url2)
(setvar "SECURELOAD" 0)
(setvar "cmdecho" 0)
(setq filePath "D:\\小辉插件\\标准模板\\领料单模版.xls")
	  (setq templateDir "D:\\小辉插件\\标准模板")
  (if (not (vl-file-directory-p templateDir))
    (CreateDir templateDir)
  )
(setq url "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/EXP.dll")
(setq url2 "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/%E9%A2%86%E6%96%99%E5%8D%95%E6%A8%A1%E7%89%88.xls")
(setq dir (strcat (getvar "ROAMABLEROOTPREFIX") "Support\\EXP.dll"))
	
(if (findfile filePath)
	  (progn
		(if (findfile dir)
			(command "NETLOAD" dir)
			(progn
	  (DownLoad url1 dir)
	  (command "NETLOAD" dir)
			)))
	 (progn
		(DownLoad url2 filePath) 
		(if (findfile dir)
			(command "NETLOAD" dir)
			(progn
	  (DownLoad url1 dir)
	  (command "NETLOAD" dir)
			)) 
	 ))	
	(princ)
	(command "Dimensiontoexcel")
	(princ)
)

;排版前检查
(defun c:jc ()
(setvar "SECURELOAD" 0)
(setvar "cmdecho" 0)
(setq url "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/EXP.dll")
	         
(setq dir (strcat (getvar "ROAMABLEROOTPREFIX") "Support\\EXP.dll"))
(if (findfile dir)
	  (command "NETLOAD" dir)
	  (progn
		(DownLoad url dir)
	 (command "NETLOAD" dir)
		))
	(princ)
	(command "Jc")
 (princ)
)
;自动排版
(defun c:pb ()
(setvar "SECURELOAD" 0)
(setvar "cmdecho" 0)
(setq url "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/EXP.dll")
	         
(setq dir (strcat (getvar "ROAMABLEROOTPREFIX") "Support\\EXP.dll"))
(if (findfile dir)
	  (command "NETLOAD" dir)
	  (progn
		(DownLoad url dir)
	 (command "NETLOAD" dir)
		))
	(princ)
	(command "Pb")
 (princ)
)
;自动调整
(defun c:tz ()
(setvar "SECURELOAD" 0)
(setvar "cmdecho" 0)
(setq url "https://gitee.com/everyone-is-drunk/first/raw/master/%E6%A0%87%E5%87%86%E5%86%85%E5%AE%B9/EXP.dll")
	         
(setq dir (strcat (getvar "ROAMABLEROOTPREFIX") "Support\\EXP.dll"))
(if (findfile dir)
	  (command "NETLOAD" dir)
	  (progn
		(DownLoad url dir)
	 (command "NETLOAD" dir)
		))
	(princ)
	(command "tz")
 (princ)
)


;插入图框 SE
(defun c:SE (/ pt1 pt2 xjl yjl xbl1 ybl1 pt0)
	(setvar "cmdecho" 0)
	(setvar "insunits" 4)
	(setq os (getvar "osmode"))
   	(setvar "osmode" 0)
	(defun Min_Max()
  
	(vla-getboundingbox(vlax-ename->vla-object end) 'minp 'maxp)
	(setq minp (vlax-safearray->list minp)
		maxp (vlax-safearray->list maxp))
	(setq minx (car minp)
		maxx (car maxp)
		miny (cadr minp)
		maxy (cadr maxp))
	(if (> minx0 minx) (setq minx0 minx))
	(if (> miny0 miny) (setq miny0 miny))
	(if (< maxx0 maxx) (setq maxx0 maxx))
	(if (< maxy0 maxy) (setq maxy0 maxy))
)
  (command "ucs" "w")
	(princ "\n请选择物体:")
	(while(null(setq object1 (ssget))))
	(setq minx0 1e6 miny0 1e6 maxx0 -1e6 maxy0 -1e6)
	(setq i 0)
	(repeat (sslength object1)
		(setq end (ssname object1 i))
		(setq end_data (entget end))
		(Min_Max)
		(setq i(1+ i))
	)
	(setq pmin (list minx0 miny0)
		    pmax (list maxx0 maxy0))
	(setq xjl (abs (- (car pmax) (car pmin))))
	(setq yjl (abs (- (cadr pmax) (cadr pmin))))
        
	 (setq xbl1  (/ xjl 870))
  	 (setq ybl1  (/ yjl 610))
  	 (if (> ybl1 xbl1)
      	 (setq xbl1 ybl1) )
    	(setq xbl1 (rtos xbl1 2 1))
   	(setq pt0 (list (/ (+ (car pmin ) (car pmax) ) 2)
                   (/ (+ (cadr pmin) (cadr pmax)) 2)))
 (command "-insert"  "标准图框3.dwg" pt0  xbl1 ""  "0" "")
				(setq en0 (entlast))
			;;此处请选有属性定义的图块
		(setq vn0 (vlax-ename->vla-object en0))
	 (setq time (rtos (getvar "Cdate") 2 6))
		(setq lstVar (vla-getattributes vn0))
		(setq lstAttrs (vlax-safeArray->list (vlax-variant-value lstVar)))
		(setq TextString nil)
		(foreach attr	lstAttrs
			(setq TagString (vla-get-TagString attr))
			(cond 
				((equal TagString "日期") (vla-put-TextString attr (strcat (substr time 1 4)"/"(substr time 5 2)"/"(substr time 7 2))))

)
)
   (setvar "osmode" os)
   (princ)
)

;快速标注板材 DD
(defun c:dd (/ sc h d  oldos oldla ss lst n obj minx miny maxx  maxy pt1 ss
							pt2 pt3 d2)                   
  (prompt "\n请选择板材")
  (setq sc (getvar "dimscale"))
  
  (setq d (getvar "dimgap"))
  (setq oldos (getvar "osmode"))
  (setq oldla (getvar "clayer"))
	  (if (not (tblsearch "LAYER" "板材"))
    (command "_.-layer" "m" "板材" "c" "7" "" "") ; 创建并设置颜色
  )
	(command "_.UNDO" "BE")
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimtxt" 37)
	(mapcar '(lambda(a / lst maxx maxy minx miny n obj pt1 pt2 pt3 ss)   
						 (setq ss(ssadd a))
						 (repeat (setq n (sslength ss))
							 (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
							 
							 (vla-put-Color  obj 7)
							  (vla-put-Layer obj "板材")
							 
							 (vla-getboundingbox obj 'x 'y)
							 (setq lst (cons (vlax-safearray->list y)
													 (cons (vlax-safearray->list x) lst)
												 )
							 )
						 )
						 (setq  minx (car (vl-sort (mapcar 'car lst) '<))
							 miny (car (vl-sort (mapcar 'cadr lst) '<))
							 maxx (car (vl-sort (mapcar 'car lst) '>))
							 maxy (car (vl-sort (mapcar 'cadr lst) '>))
						 )
						 (setq pt1 (list minx miny))
						 (setq pt2 (list minx maxy))
						 (setq pt3 (list maxx maxy))
						 
						 
						 (command "dimlinear"
							 pt1
							 pt2
							 (polar pt1 (+ (* -1.5 pi) (angle pt1 pt2)) 150)
						 )
						 (command "dimlinear"
							 pt2
							 pt3
							 (polar pt2 (+ (* -1.5 pi) (angle pt2 pt3)) 150)
						 )
					 )
		(vl-remove-if-not '(lambda(x)(= 'ENAME (type x))) (mapcar 'cadr (ssnamex (ssget":S"'((0 . "*polyline")(420 . 255))))))
		
	)
  
  (setvar "osmode" oldos)
  (setvar "clayer" oldla)
  (setvar "cmdecho" 1)
  (command "_.UNDO" "E")
  (princ)
)

;删除所有标注.中心线层.序号图层,变1mm的线为黄色  ES
(defun C:es(/ a en k nu obj s)
   (command "._undo" "_begin")
	 (setvar "cmdecho" 0) ;关闭普通命令提示信息
   (setvar "osmode"  0)  ;关闭对象捕捉状态  
(setq s	(ssget '(
      (-4 . "<OR")      
      (0 . "DIMENSION,ARC_DIMENSION,line") 
      (8 . "序号图层,3中心线层") 
      (-4 . "OR>") 
    )))
	(setq nu (sslength s)
			    k 0)				 
    (while (< k nu)
    (setq en (entget (setq a (ssname s k))))
    
    (if (= (cdr (assoc 0 en)) "LINE")
    (progn
    (setq obj (vlax-ename->vla-object (ssname s k)))
    (if  (equal (vlax-get obj 'Length) 1 0.05)
         (progn
	   (vla-put-Color obj 2)
           ))))
	(if (or (= (cdr (assoc 0 en)) "DIMENSION") (= (cdr (assoc 0 en)) "ARC_DIMENSION")  (= (cdr (assoc 8 en)) "序号图层")(= (cdr (assoc 8 en)) "3中心线层"))
         (progn
				 (vla-delete (vlax-ename->vla-object a))))		
      (setq k (+ k 1)))	

    
 
 (setvar "osmode" 16383)  ;打开对象捕捉状态
 (command "._undo" "_end")   
	 (princ)
    )

;连续标注优化版 DS
(DEFUN C:ds (/ ang pt1 pt2 pt3)
 (INITGET 9)
 (SETQ PT1 (GETPOINT "\n尺寸界限第一点 :"))
 (INITGET 9)
 (SETQ PT2 (GETPOINT PT1 "\n尺寸界限第二点 :"))
 (COMMAND "_DIMLINEAR" PT1 PT2 PAUSE)
 (SETQ ANG (CDR (ASSOC 50 (ENTGET (ENTLAST)))))
 (COMMAND "_DIMCONTINUE")
 (WHILE (SETQ PT3 (GETPOINT "\n 第二点 :"))
  (IF (EQUAL ANG 0.0 1E-3)
   (SETQ PT3 (LIST (CAR PT3) (CADR PT2) 0.0))
   (SETQ PT3 (LIST (CAR PT2) (CADR PT3) 0.0))
  )
  (COMMAND PT3)
 )
 (COMMAND "" "")
 (PRINC)
)

;快速调整文字高度 ZG
(defun C:zg (/ n s ent obj currH newH)
  (if (setq s (ssget '((0 . "MTEXT,TEXT")))) ; 简化选择集过滤条件[6,7](@ref)
    (progn
      (setq ent (ssname s 0)) ; 获取第一个图元用于读取默认高度
      (setq obj (vlax-ename->vla-object ent))
      (setq currH (vla-get-Height obj)) ; 获取当前高度作为默认值[5](@ref)
      (initget 6) ; 禁止空输入和零值
      (setq newH (getint (strcat "\n新高度<" (rtos currH) ">: "))) ; 添加默认值提示
      (setq newH (cond (newH) (T currH))) ; 处理空输入（直接回车保留默认值）
      (repeat (setq n (sslength s)) ; 批量修改高度
        (vla-put-Height
          (vlax-ename->vla-object (ssname s (setq n (1- n))))
          newH
        )
      )
    )
  )
  (princ)
)

;框选成块 SE
(DEFUN C:SB  () 
(setq a1 (getvar "insbase"))  
(setq object1 (ssget))
(command "copybase" a1 object1 "")
(command "pasteblock" a1 "")
(command "erase" object1 "")
)

;变更图层为“3中心线层"
(Defun C:r3 (/ laynam)
  (setq LayNam "3中心线层");图层名称
  (if (/= (last (ssgetfirst)) nil);如果选择集为空
    (progn
      (command "chprop" (ssget) "" "la" LayNam "color" "bylayer" "ltype" "bylayer" "lweight" "bylayer" "")
      ;将所选对象移动到指定图层，并设置对象特性随层  
    )    
  )
  (princ)
)

;设置颜色
;颜色变成红色
(defun c:1(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "1" ""))
;颜色变成黄色
(defun c:2(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "2" "")
)
;颜色变成绿色
(defun c:3(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "3" "")
)
;颜色变成青色
(defun c:4(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "4" "")
)
;颜色变成蓝色
(defun c:5(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "5" "")
)
;颜色变成洋红
(defun c:6(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "6" "")
)
;颜色变成白色
(defun c:7(/ ent)
  (setq ent (ssget))
  (command "change" ent "" "p" "c" "7" "")
)

;生成最小矩形框
(defun C:xjx(/ en end end_data i maxx0 maxy0 min_max minx0 miny0 pmax pmin)
	(vl-load-com)
	(command "undo" "be")
        
	(setvar "cmdecho" 0)
	(command "ucs" "w")
	(defun Min_Max()
	(vla-getboundingbox(vlax-ename->vla-object end) 'minp 'maxp)
	(setq minp (vlax-safearray->list minp)
		maxp (vlax-safearray->list maxp))
	(setq minx (- (car minp) 5)
		maxx (+ (car maxp) 5)
		miny (- (cadr minp) 5)
		maxy (+ (cadr maxp) 5))
	(if (> minx0 minx) (setq minx0 minx))
	(if (> miny0 miny) (setq miny0 miny))
	(if (< maxx0 maxx) (setq maxx0 maxx))
	(if (< maxy0 maxy) (setq maxy0 maxy))
)
	(princ "\n请选择物体:")
	(while(null(setq en (ssget))))
	(setq minx0 1e6 miny0 1e6 maxx0 -1e6 maxy0 -1e6)
	(setq i 0)
	(repeat (sslength en)
		(setq end (ssname en i))
		(setq end_data (entget end))
		(Min_Max)
		(setq i(1+ i))
	)
	(setq pmin (list minx0 miny0)
		pmax (list maxx0 maxy0))
	(command ".rectang" "non" pmin "non" pmax)
	(command "undo" "e")
	(princ)
)

;板材重量计算
(defun c:zl(/ d1 dcl_file dcl_id getdata1 make-dclcs md re zld0 zld1 zld2 zld3)
	(defun make-dclCS  (/ lst_str str file f);;面板的界面显示dcl
		(setq lst_str
			'(
				 "重量计算:dialog"
				 "{ // start dcl"
				 "label = \"重量计算\";"
				 ":column{"
				 ":row{:edit_box{label=\"板材长度：\";key=\"d0\"; edit_width=12;}}"
				 ":row{:spacer{height=0.1;fixed_width=true;}}"
				 ":row{:edit_box{label=\"板材宽度：\";key=\"d1\"; edit_width=12;}}"
				 ":row{:spacer{height=0.1;fixed_width=true;}}"
				 ":row{:edit_box{label=\"板材厚度：\";key=\"d2\"; edit_width=12;is_tab_stop = false;}}"
				 ":row{:spacer{height=0.1;fixed_width=true;}}"
				 ":row{:popup_list{label=\"板材材质\";key=\"d3\";list=\"SUS304(7.93)\\nQ235B(7.85)\\n镀锌板(7.9)\\n316L(7.98)\";is_tab_stop = false;}}"
				 "}"
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\";
				 is_default=true;height=2;}"	":button{label=\"取消(&C)\";key=\"cancel\";is_cancel=true;height=2;}""}"
				 "fixed_width=true;"
				 "alignment=left;"
				 "} // end dll" ;结尾
			 )
		)
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(h-read1 "zl")
	;;---------开始写面板调用函数
	(if (= nil  zld0)
      (progn (setq zld0 1219)
				     (setq zld1 4000)
				     (setq zld2 1.5)
				     (setq zld3 0)
			))
  (defun getdata1()
		(setq zld0  (atof(get_tile "d0")))   
    (setq zld1  (atof(get_tile "d1")))
    (setq zld2  (atof(get_tile "d2")))
    (setq zld3  (atoi(get_tile "d3")))
	)
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "重量计算" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
      ;设置d1为焦点
	(set_tile "d0" (rtos zld0 2 2))
	(set_tile "d1" (rtos zld1 2 2))
	(set_tile "d2" (rtos zld2 2 2))
	  (if (/= zld3 nil)
  (set_tile "d3" (rtos zld3 2 2)));材质

  (mode_tile "d0" 2)
  (action_tile "accept" "(getdata1)(done_dialog 1)")
  (action_tile "cancel" "(getdata1)(done_dialog 0)")
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (if (= re 1)
		(progn
		(cond ((= zld3 0) (setq md 7.93))
			    ((= zld3 1) (setq md 7.85))
			    ((= zld3 2) (setq md 7.9))
			    ((= zld3 3) (setq md 7.98)))
		(setq d1  (strcat " 当前板材的面积为" (rtos(* (/ (* zld0 zld1) 1000000))) "m2"  " \n 重量为" (rtos(* (/ (* zld0 zld1) 1000000)	md zld2)) "kg"))
		(h-save1 '(zld0 zld1 zld2 zld3) "zl")
		(print d1)
		(alert d1)						
		)
	)
	(princ)
)

;板材重量计算2
(defun c:ZL1(/ ename i l ml-length modelspace obj pt0 ss totalarea totlength) ;引用函数，
  (vl-load-com)
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
	(defun ml-length (ename / j d ptlist)
        (foreach n (entget ename)
                (if (= (car n) 11)
                        (setq ptlist (cons (cdr n) ptlist))
                )
        )
        (reverse ptlist)
        (setq j 0 d 0)
        (repeat (1- (length ptlist))
                (setq d (+ d (distance (nth j ptlist) (nth (1+ j) ptlist))))
                (setq j (1+ j))
        )
        d
)
  ;(command "area" "o" (car (entsel)))
  (if 
  (setq ss (ssget))
  (progn
  (setq pt0(getpoint"请点击插入的位置:"))
  (setq modelspace (vla-get-Modelspace (vla-get-activeDocument (vlax-get-acad-object))))
  (setq l (sslength ss) i 0 totalarea 0 totlength 0)
  (repeat l
 (setq ename (ssname ss i))
 (setq obj (vlax-ename->vla-object ename))
 (if (vlax-property-available-p obj "area")
 (setq totalarea (+ (vlax-get-property obj 'area) totalarea)))
        (if (= (cdr (assoc 0 (entget ename))) "MLINE")
        (setq totlength (+ totlength (ml-length ename)))
        (setq totlength (+ totlength (vlax-curve-getdistatparam ename (vlax-curve-getendparam ename))))
        )
        (setq i (1+ i)))

(entmake (list '(0 . "TEXT")(cons 1 (strcat "总面积为: " (rtos (/ totalarea 1000000) 2 2) "㎡"))(cons 10 pt0)(cons 40 200) (cons 62  7)))
(entmake (list '(0 . "TEXT")(cons 1 (strcat "总长度为: " (rtos (/ totlength 1000) 2 2) "m"))(cons 10 (list (car pt0) (- (cadr pt0)400)))(cons 40 200) (cons 62  7)))
(entmake (list '(0 . "TEXT")(cons 1 (strcat "总重量为：" (rtos (/ (* totalarea 7.93 5.0 ) 1000000) 2 2) "kg"))(cons 10 (list (car pt0) (- (cadr pt0)800)))(cons 40 200) (cons 62  7)))))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ))

;原位复制
(defun c:cv(/ hh pa pb pc pd ww)
	 (setvar "cmdecho" 0)
	 (setvar "blipmode" 0)	
	(command "copybase" '(0 0 0) (ssget) "" "PASTECLIP" '(0 0 0))
	(prompt "\n 原位复制")
	(prompt "\n <<c:Original copy>>原位复制")
	(prin1)
	)

;获取两条线的中点线
(defun c:tx(/ hh:picksegendpt i mat:vxs n obj1 obj2 pl1 pl1lst pl2 pl2lst pl3 pl4 pt1 pt2 u v)
	(defun MAT:vxs ( v s )
  (mapcar (function (lambda ( n ) (* n s))) v)
)

(defun HH:PickSegEndPt (obj p / n pp)
(cond 
	((= (cdr (assoc 0 (entget obj))) "LWPOLYLINE")
  (setq pp (vlax-curve-getclosestpointto obj (trans p 1 0))
 n  (fix (vlax-curve-getparamatpoint obj pp))
  )
  (list (vlax-curve-getPointAtParam obj n)
 (vlax-curve-getPointAtParam obj (1+ n))
  )
)
 ((= (cdr (assoc 0 (entget obj))) "LINE")
	 (list 
		 (cdr (assoc 10 (entget obj)))
		 (cdr (assoc 11 (entget obj)))
	 )
	 )
)
)

(if (and (setq obj1 (entsel "点取直线段1:") obj2 (entsel "点取直线段2:")))
(progn
(setq pl1lst (HH:PickSegEndPt (car obj1) (cadr obj1)))
(setq pl2lst (HH:PickSegEndPt (car obj2) (cadr obj2)))
(setq pl1 (car pl1lst) pl2 (cadr pl1lst))
(setq pl3 (car pl2lst) pl4 (cadr pl2lst))
(if (inters pl1 pl3 pl2 pl4) (mapcar 'set '(pl1 pl2 pl3 pl4) (LIST pl1 pl2 pl4 pl3)))
(SETQ U (MAPCAR '- PL3 PL1));;
(SETQ V (MAPCAR '- PL4 PL2));;
(setq n (getint "\n输入等分数<2>:"))
(if (not n)
  (progn
  (setq n 2)))

(setq i 1)
(repeat (- N 1)
(SETQ PT1 (MAPCAR '+ pL1 (MAT:vxs U (* i (/ 1.0 N)))));;
(SETQ PT2 (MAPCAR '+ pL2 (MAT:vxs V (* i (/ 1.0 N)))));;
(entmake (list '(0 . "line")(cons 62 6)(cons 10 PT1)(cons 11 PT2)))
(setq i (1+ i))
)
)
)
(princ)
)

;生成物体外形最小矩形框
(defun C:xjx(/ en end end_data i maxx0 maxy0 min_max minx0 miny0 pmax pmin)
	(vl-load-com)
	(command "undo" "be")
        
	(setvar "cmdecho" 0)
	(command "ucs" "w")
	(defun Min_Max()
	(vla-getboundingbox(vlax-ename->vla-object end) 'minp 'maxp)
	(setq minp (vlax-safearray->list minp)
		maxp (vlax-safearray->list maxp))
	(setq minx (- (car minp) 5)
		maxx (+ (car maxp) 5)
		miny (- (cadr minp) 5)
		maxy (+ (cadr maxp) 5))
	(if (> minx0 minx) (setq minx0 minx))
	(if (> miny0 miny) (setq miny0 miny))
	(if (< maxx0 maxx) (setq maxx0 maxx))
	(if (< maxy0 maxy) (setq maxy0 maxy))
)
	(princ "\n请选择物体:")
	(while(null(setq en (ssget))))
	(setq minx0 1e6 miny0 1e6 maxx0 -1e6 maxy0 -1e6)
	(setq i 0)
	(repeat (sslength en)
		(setq end (ssname en i))
		(setq end_data (entget end))
		(Min_Max)
		(setq i(1+ i))
	)
	(setq pmin (list minx0 miny0)
		pmax (list maxx0 maxy0))
	(command ".rectang" "non" pmin "non" pmax)
	(command "undo" "e")
	(princ)
)

;生成物体外形矩形框(宽度方向可调)
(defun C:xjx1 (/ *error* en end end_data i minp maxp minx miny maxx maxy minx0 miny0 maxx0 maxy0 pmin pmax width0 user_width)
    (vl-load-com)
    (command "undo" "be")
    (setvar "cmdecho" 0)
    (command "ucs" "w")
    
    ;; 错误处理函数
    (defun *error* (msg)
        (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
            (princ (strcat "\n错误: " msg))
        )
        (command "undo" "e")
        (princ)
    )
    
    ;; 计算包围框函数
    (defun Min_Max (ent / obj)
        (setq obj (vlax-ename->vla-object ent))
        (vla-getboundingbox obj 'minp 'maxp)
        (setq minp (vlax-safearray->list minp)
              maxp (vlax-safearray->list maxp))
        (setq minx (- (car minp) 5)
              maxx (+ (car maxp) 5)
              miny (- (cadr minp) 5)
              maxy (+ (cadr maxp) 5))
        (if (> minx0 minx) (setq minx0 minx))
        (if (> miny0 miny) (setq miny0 miny))
        (if (< maxx0 maxx) (setq maxx0 maxx))
        (if (< maxy0 maxy) (setq maxy0 maxy))
    )
    
  (princ "\n请选择物体: ")
    (while (null (setq en (ssget)))) ; 等待用户选择
        
    (setq minx0 1e6 miny0 1e6 maxx0 -1e6 maxy0 -1e6) ; 初始化极值
    (setq i 0)
    (repeat (sslength en)
        (setq ent (ssname en i))
        (Min_Max ent) ; 计算包围框
        (setq i (1+ i))
    )
    
    ;; 计算Y轴方向的原始宽度
    (setq width_y (- maxy0 miny0))
    (setq pmin (list minx0 miny0))
    
    ;; 获取用户输入板宽（Y轴方向）
    (initget 6) ; 禁止负值和零值
    (setq user_width
        (getreal 
            (strcat "\n请输入板宽 (Y轴方向，最小 " (rtos width_y 2 2) "): ")
        )
    )
    
    ;; 验证输入值
    (while (< user_width width_y)
        (alert (strcat "板宽必须大于等于 " (rtos width_y 2 2)))
        (initget 6)
        (setq user_width
            (getreal 
                (strcat "\n请输入板宽 (Y轴方向，最小 " (rtos width_y 2 2) "): ")
            )
        )
    )
    
    ;; 创建新矩形（X轴保持自动计算，Y轴使用用户输入值）
    (setq pmax (list maxx0 (+ miny0 user_width))) 
    (command "_.rectang" "_non" pmin "_non" pmax)
    
    (command "undo" "e")
    (princ)
)

;统计文字内容和次数
(defun c:textstat (/ ss lst pairs pt basePt rowHeight txtHeight)
  ;; 创建选择集（框选单行文字）
  (if (setq ss (ssget '((0 . "TEXT"))))
	 ;; 收集所有文字内容
    (progn (setq lst '())
    (repeat (setq i (sslength ss))
       (setq  ent (ssname ss (setq i (1- i)))
         txt (cdr (assoc 1 (entget ent)))
         lst (cons txt lst)))
      ;; 统计内容出现次数      
 (setq pairs '())      
(foreach txt lst
        (if (setq cnt (assoc txt pairs))
          (setq pairs (subst (cons txt (1+ (cdr cnt))) cnt pairs))
          (setq pairs (cons (cons txt 1) pairs))
        )
      )
      ;; 按数量降序排序
      (setq pairs (vl-sort pairs (function (lambda (a b) (> (cdr a) (cdr b))))))
      ;; 用户点选插入基点
      (setq basePt (getpoint "\n点击统计结果插入位置: "))

          ;; 设置文字参数
          (setq rowHeight 300  ; 行间距
                txtHeight 100   ; 文字高度
                i 0)
          ;; 生成统计结果文字			
          (foreach pair pairs          
					(entmakex (list '(0 . "TEXT") (cons 1 (strcat (car pair) "  " (itoa (cdr pair)) "个"))(cons 10 (polar basePt (* pi 1.5) (* rowHeight i))) (cons 11 (polar basePt (* pi 1.5) (* rowHeight i)))
					(cons 72  1) (cons 73 2)(cons 40 txtHeight)(cons 62 7)))
					(setq i (1+ i))
					)
						
          (princ (strcat "\n已生成 " (itoa (length pairs)) " 行统计文字"))
        )
     (princ "\n未选择单行文字。") 
    )
    
  
  (princ))

;打开金蝶云
(defun c:jdy (/ dir url)		
  (startapp "explorer" "http://erp.zhaohegroup.com:8008/k3cloud/html5/index.aspx"))

;选择两个点生成刻线
(defun c:xs(/ ent1 ent2 pt1 pt2 ss)
  (setvar "cmdecho" 0)
  (setvar "osmode" 0) 
(setq ss (ssget '((0 . "point"))) 
     ent1 (ssname ss 0)
     pt1 (cdr (assoc 10 (entget ent1)))
	   ent2 (ssname ss 1) 
	   pt2(cdr (assoc 10 (entget ent2))))
	(MK-line3 (list pt1 pt2) 1 "3中心线层")
	(entmake (list '(0 . "line") (cons 10 pt1) (cons 62 2) (cons 11 (polar pt1 (angle pt1 pt2) 1))))
	(entmake (list '(0 . "line") (cons 10 pt2) (cons 62 2) (cons 11 (polar pt2 (angle pt1 pt2) -1))))
    (setvar "osmode" 16383)  
  (princ)
)

;在直线两端打点(参数版)
(defun c:tt (/ d1 e p1 p2 s)
	 (setq s (ssget  '((0 . "*LINE"))))
				(setq d1(getreal "请设置刻线长度<1>") )
			(if (not d1) (setq d1 1))
    (while(setq e(ssname s 0))
      (setq p1(vlax-curve-getstartpoint e)
            p2(vlax-curve-getendpoint e))

			(MK-line3 (list p1 p2) 1 "3中心线层")
      (entmakex(mapcar'cons'(0 8 62 10 11)(list"line" "0" 2 p1 (polar p1(angle p1 p2) d1))))
      (entmakex(mapcar'cons'(0 8 62 10 11)(list"line" "0" 2 p2 (polar p2(angle p2 p1) d1))))
      (ssdel e s)(entdel e))
  (print "已成功打点！！！")
  (princ)	
)

;在直线两端打点(1mm)
(defun c:tt1 (/ d e p1 p2 s)
	
(setq s (ssget  '((0 . "*LINE"))))
(while(setq e(ssname s 0))
      (setq p1(vlax-curve-getstartpoint e)
            p2(vlax-curve-getendpoint e))
			(MK-line3 (list p1 p2) 1 "3中心线层")
      (entmakex(mapcar'cons'(0 8 62 10 11)(list"line" "0" 2 p1 (polar p1(angle p1 p2) 1))))
      (entmakex(mapcar'cons'(0 8 62 10 11)(list"line" "0" 2 p2 (polar p2(angle p2 p1) 1))))
      (ssdel e s)(entdel e))
  (princ)	
)

;插入当前时间
(defun c:bb()
        (setq time (rtos (getvar "Cdate")2 6))
        (setq d1 (strcat (substr time 5 2) "月" (substr time 7 2) "日" (substr time 10 2) "时" (substr time 12 2) "分" (substr time 14 2) "秒"))
  (setq pt0 (getpoint "插入点"))
(command "text" "m" pt0 50 0(setq d1 (strcat (substr time 5 2) "月" (substr time 7 2) "日" (substr time 10 2) "时" (substr time 12 2) "分" (substr time 14 2) "秒"))))

;关闭且不保存出当前活动文档外的所有文档
(defun c:off (/ acadApp docs activeDoc doc)
    (vl-load-com)
    
    (setq acadApp (vlax-get-acad-object)
          docs (vla-get-documents acadApp)
          activeDoc (vla-get-activedocument acadApp)
    )
    
    (vlax-for doc docs
        (if (not (equal doc activeDoc))
            (vla-close doc :vlax-false)
        )
    )
    
    (princ "\n其他文档已关闭，未保存更改。")
    (princ)
)

;选择所有标注
(defun c:xm(/ ) 
(if(setq ss(ssget '((0 . "DIMENSION,ARC_DIMENSION,LEADER"))))(sssetfirst ss ss))
(princ))

;选择所有文字
(defun c:xz()
(setvar "cmdecho" 0)
(setq ss (ssget '((0 . "TEXT,MTEXT"))))
(sssetfirst ss ss)
(princ)
)

;打断相交图元
(defun c:bs (/ break_with cmd ss)
  (command "._undo" "_begin")
  (setq cmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
	
	(defun break_with (ss2brk ss2brkwith self / cmd intpts lst masterlist ss ssobjs
											onlockedlayer ssget->vla-list list->3pair
											get_interpts break_obj
										)
		(vl-load-com)
		(defun onlockedlayer (ename / entlst)
			(setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
			(= 4 (logand 4 (cdr (assoc 70 entlst)))))			
		(defun ssget->vla-list (ss / i ename lst)
			(setq i -1)
			(while (setq ename (ssname ss (setq i (1+ i))))
				(setq lst (cons (vlax-ename->vla-object ename) lst))
			) lst )
		(defun list->3pair (old / new)
			(while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
							 old (cdddr old)))
			(reverse new))
		(defun get_interpts (obj1 obj2 / iplist)
			(if (not (vl-catch-all-error-p
								 (setq iplist (vl-catch-all-apply
																'vlax-safearray->list
																(list
																	(vlax-variant-value
																		(vla-intersectwith obj1 obj2 acextendnone)
																	))))))				iplist))
		(defun break_obj (ent brkptlst / brkobjlst en enttype maxparam closedobj
											 minparam obj obj2break p1param p2 p2param
										 )
			
			(setq obj2break ent
        brkobjlst (list ent)
        enttype   (cdr (assoc 0 (entget ent)))
			)
			
			(foreach brkpt brkptlst
				(if brkobjlst
					(progn
					
						(if (not (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj2break brkpt)))
								)
							(foreach obj brkobjlst
								(if (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj brkpt)))
									(setq obj2break obj)
								)
							)
						)
					)
				)
				(cond
					((and (= "SPLINE" enttype)
						 (vlax-curve-isclosed obj2break))
						(setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
							p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
						)
						(command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
					)
					((= "CIRCLE" enttype)
						(setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
							p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
						)
						(command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
						(setq enttype "ARC")
					)
					((and (= "ELLIPSE" enttype)
						 (vlax-curve-isclosed obj2break))
						(setq p1param  (vlax-curve-getparamatpoint obj2break brkpt)
							p2param  (+ p1param 0.000001)
							minparam (min p1param p2param)
							maxparam (max p1param p2param)
							obj      (vlax-ename->vla-object obj2break)
						)
						(vlax-put obj 'startparameter maxparam)
						(vlax-put obj 'endparameter (+ minparam (* pi 2)))
					)
					(t
						(setq closedobj (vlax-curve-isclosed obj2break))
						(command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans brkpt 0 1))
						(if (not closedobj)
							(setq brkobjlst (cons (entlast) brkobjlst))
						)
					)
				)
			)
		)
    (if (and ss2brk ss2brkwith)
			(progn
				(foreach obj (ssget->vla-list ss2brk)
					(if (not (onlockedlayer (vlax-vla-object->ename obj)))
						(progn
							(setq lst nil)
							(foreach intobj (ssget->vla-list ss2brkwith) 
								(if (and (or self (not (equal obj intobj)))
											(setq intpts (get_interpts obj intobj))
										)
									(setq lst (append (list->3pair intpts) lst))
								)
							)
							(if lst
								(setq masterlist (cons (cons (vlax-vla-object->ename obj) lst) masterlist))
							)
						)
					)
				)
				
				(if masterlist
					(foreach obj2brk masterlist
						(break_obj (car obj2brk) (cdr obj2brk))
					)
				)
      )
		)	
	)
	
  (prompt "\n注意选择的所有图元都会被打断奥？")
  (if (setq ss (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
     (Break_with ss ss nil)
  )
  (setvar "CMDECHO" cmd)
  (command "._undo" "_end")
  (princ)
)

;格式刷字体
(defun c:mz(/ ent)
(command "MATCHPROP" (while (= ent nil)(setq ent (entsel "选择源对象"))) (ssget '((0 . "*text*"))) "")
)

;格式刷标注
(defun c:mx(/ ent)
(command "MATCHPROP" (while (= ent nil)(setq ent (entsel "选择源对象"))) (ssget '((0 . "DIMENSION"))) "")
)

;设置当前绘图环境为经典模式
(defun c:jdms ()

(SETVAR "VTENABLE" 0 );该命令可启用平滑转换来切换显示区域，默认值是3，我们可以将其设为0，以此加快启动速度
(SETVAR "STARTUP" 2 );启动与新建时 不加载功能区，呈现开始选项卡 (如果开始选项卡被禁用，则软件空载启动)
(setvar "startmode" 0) ;关闭开始选项卡，默认
(SETVAR "attreq" 0);关闭复制块时属性文字一直弹出来
(SETVAR "CURSORSIZE" 80);设置十字光标大小
(setvar "PICKBOX" 15)  ; 设置拾取框大小为15
(setvar "GRIPSIZE" 10) ; 设置夹点大小为10	
(SETVAR "APERTURE" 20);对置自动捕捉靶框大小为20
(SETVAR "isavebak" 0);不创建备份
(SETVAR "sigwarn" 0);取消数字签名
(SETVAR "lispsys" 0);解决autolisp扩展无法下载问题
(setenv "defaultformatforsave" "12");设置cad默认保存文件格式2000(24-2004,36-2007,48-2010,60-2013，64-2013),命令行用(getenv"DefaultFormatForSave")查看，默认nil
(setvar "gridmode" 0) ;关闭栅格-即f7，默认1
(setvar "gripmultifunctional" 1);动态夹点菜单关闭(适用于cad2010及更高版本)，默认3
(setvar "isavebak" 0);控制备份文件 (bak) 的创建。1-创建, 0-不创建，默认1
(setvar "mbuttonpan" 1) ;控制定点设备上的第三个按钮或滚轮的行为,0支持自定义文件中定义的操作,1当按住并拖动按钮或滑轮时，支持平移操作，默认1
(setvar "proxynotice" 1) ;不显示代理图形警告，默认0
(setvar "proxyshow" 1) ;不显示代理图形，默认0
(setvar "TRIMEXTENDMODE" 0);修建命令高版本调整成低版本的框交
(vl-cmdf "displayviewcubein2d" "off" );关闭东南西北
(SETVAR "DYNMODE" 3 );0关闭所有动态输入功能（包括动态提示）1打开指针输入2打开标注输入3同时打开指针和标注输入
(SETVAR "SHORTCUTMENU" 0 );初始值:11;0禁用所有默认模式、编辑模式和命令模式的快捷菜单。1启用默认模式的快捷菜单。2启用编辑模式的快捷菜单。4一旦有命令处于活动状态，就可以启用命令模式的快捷菜单。8仅当命令选项当前于命令提示下可用时，才启用命令模式的快捷菜单。16当以足够长的时间按下定点设备上的右键时，才会显示快捷菜单
(SETVAR "QPMODE" 0 );0在绘图区域中选择了所有对象时，关闭所有对象的“快捷特性”选项板的显示1在绘图区域中选择了所有对象时，打开所有对象的“快捷特性”选项板的显示2打开“快捷特性”选项板的显示，但仅对于在“自定义用户界面 (CUI)” 编辑器中受支持的对象，以便当它们在图形区域中选定时显示“快捷特性”
(SETVAR "QPLOCATION" 0 );0在相对于光标的位置显示“快捷特性”选项板1在与光标无关的固定位置显示“快捷特性”选项板
(SETVAR "MENUBAR" 1 );隐藏菜单栏1显示菜单栏
(command "commandline" );显示“命令”窗口。
(SETVAR "SELECTIONPREVIEW" 2 );控制选择预览的显示。0关闭1当无激活的命令时开2当命令提示选择对象时开
(command "ribbonclose" )
(command "TOOLBAR" "图层" "S")
(command "TOOLBAR" "特性" "S")
(command "TOOLBAR" "样式" "S")
(command "taskbar" "0");控制多个打开的图形在 Windows 任务栏上是单独显示还是被编组。
(command "LAYLOCKFADECTL" "0");锁定的图层不淡显
(command "-osnap" "int,cen,per,endp,mid,qua,nea");设置常用捕捉
(command "XDWGFADECTL" "0");控制外部参照淡显度
(command "-wssave" "AutoCAD 经典" "y")
(princ)
)

;悬挂端连线
(defun c:sd (/ p1 p2 ptn singlexgx ss)
  (defun SingleXGX (s1 / p1 p2 ss1 ss2 n1 n2)
    (setq p1  (vlax-curve-getStartPoint s1)
	  p2  (vlax-curve-getEndPoint s1)
	  ss1 (ssget "c" p1 p1)
	  ss2 (ssget "c" p2 p2)
	  n1  (sslength ss1)
	  n2  (sslength ss2)
    )
    (if	(and (or (= n1 1)
		 (= n2 1)
	     )
	     (/ n1 n2)
	)
      (if (= n1 1)
	p1
	p2
      )
    )
  )
  (setvar 'cecolor "7")
  (setq	ss  (ssget '((0 . "line,lwpolyline,arc")))
	ptn (mapcar 'cadr (cdr (reverse (ssnamex ss))))
	ptn (mapcar 'SingleXGX ptn)
	ptn (vl-remove nil ptn)
	ptn (vl-sort ptn '(lambda (x y) (< (car x) (car y))))
  )
  (while (and (setq p1 (car ptn))
	      (setq p2 (cadr ptn))
	 )
    (setq ptn (cddr ptn))
    (command "line" "non" p1 "non" p2 "")
  )
  (princ)
)

;文字对齐
(defun c:dqa (/ m pzj:chaligncur pzj:dqth pzj:dqts pzj:sort)
(vl-load-com)
;文字纵向对齐
(defun pzj:dqts(ss dqpt space / i boxpt lst spz)
  (setq i 0)
  (repeat (sslength ss)
    (pzj:chalignCur (entget (ssname ss i)));文字改为左对齐
    (setq
      boxpt (textbox (entget (ssname ss i)))
      lst (cons (list
      (ssname ss i)
      (cdr (assoc 10 (entget (ssname ss i))))
      (cdr (assoc 40 (entget (ssname ss i))))
    )
      lst
    );构建((图元名1 对齐点1 字高1) (图元名2 对齐点2 字高2)...)列表
      lst (vl-sort lst '(lambda(a b) (> (nth 1 (nth 1 a)) (nth 1 (nth 1 b)))));((图元名1 对齐点1 字高1) (图元名2 对齐点2 字高2)...)列表按轴排序，升序(x轴m=0、y轴m=1、z轴m=2) 
    )
    (setq i (1+ i))
  )
  
  (setq spz 0)
  (foreach each lst
    (if (= space nil)
      (vla-move (vlax-ename->vla-object (nth 0 each)) (vlax-3d-point (nth 1 each)) (vlax-3d-point (list (car dqpt) (cadr (nth 1 each)) (caddr (nth 1 each)))))
      (progn
        (vla-move (vlax-ename->vla-object (nth 0 each)) (vlax-3d-point (nth 1 each)) (vlax-3d-point (list (car dqpt) (- (cadr dqpt) spz) (caddr dqpt))))
        (setq spz (+ (+ (nth 2 each) space) spz))
      )
    )
  )
)
 ;文字横向对齐
(defun pzj:dqth(ss dqpt space / i boxpt lst sph)
  (setq i 0)
  (repeat (sslength ss)
    (pzj:chalignCur (entget (ssname ss i)));文字改为左对齐
    (setq
      boxpt (textbox (entget (ssname ss i)))
      lst (cons (list
      (ssname ss i)
      (cdr (assoc 10 (entget (ssname ss i))))
      (1+ (fix (- (nth 0 (nth 1 boxpt)) (nth 0 (nth 0 boxpt)))))
    )
      lst
    );构建((图元名1 对齐点1 字长1) (图元名2 对齐点2 字长2)...)列表
      lst (vl-sort lst '(lambda(a b) (< (nth 0 (nth 1 a)) (nth 0 (nth 1 b)))));((图元名1 对齐点1 字长1) (图元名2 对齐点2 字长2)...)列表按x轴排序，升序 
    )
    (setq i (1+ i))
  )
  (setq sph 0)
  (foreach each lst
    (if (= space nil)
      (vla-move (vlax-ename->vla-object (nth 0 each)) (vlax-3d-point (nth 1 each)) (vlax-3d-point (list (car (nth 1 each)) (cadr dqpt) (caddr (nth 1 each)))))
      (progn
        (vla-move (vlax-ename->vla-object (nth 0 each)) (vlax-3d-point (nth 1 each)) (vlax-3d-point (list (+ (car dqpt) sph) (cadr dqpt) (caddr dqpt))))
  (setq sph (+ (+ (nth 2 each) space) sph))
      )
    )
  )
  (princ)
) 
	;更改文字为左对齐
(defun pzj:chalignCur(ent)
  (if (not (= (assoc 72 ent) 0))
    (setq ent (entmod (subst (cons 72 0) (assoc 72 ent) ent)))
  )
  (princ)
)
	;根据参数返回点列表按某一坐标轴排序，ordor=1为降序，=0为升序
	(defun pzj:sort(ptlst axis ordor / tmp)
  (setq tmp
    (cond
      ((= axis "x") (vl-sort ptlst '(lambda(a b) (< (car a) (car b)))))
      ((= axis "y") (vl-sort ptlst '(lambda(a b) (< (cadr a) (cadr b)))))
      ((= axis "z") (vl-sort ptlst '(lambda(a b) (< (caddr a) (caddr b)))))
    )
  )
  (if (= ordor 1)
    (reverse tmp)
    tmp
  )
)
	(initget "s")
  (setq m (getkword "(s)竖向对齐/横向对齐："))
  (if (= m "s")
		(pzj:dqth (ssget ":L" '((0 . "TEXT"))) (getpoint "\n指定对齐点：") (getreal"\n指定间距:"))
    (pzj:dqts (ssget ":L" '((0 . "TEXT"))) (getpoint "\n指定对齐点：") (getreal"\n指定间距:"))   
  )
  (princ)
)

;生成对齐板
(defun c:dqb ()
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
  (setq pt0 (getpoint "请输入插入点")
		    p1 (list (+ (car pt0) 50000) (cadr pt0))
	)
	
	(repeat 12
		(MK-line1 (list pt0 p1))
		(setq pt0 (list (car pt0) (- (cadr pt0) 3000))
		      p1 	(list (car p1) (- (cadr p1) 3000)))	
	)
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")	
)

;调整标注小数位数
(defun c:dr (/ ss dec input)
  ;;; 获取用户输入的小数位数（默认0）
  (setq input (getstring "\n请输入小数位数 <0>: "))  ; 提示输入
  (cond
    ((= input "") (setq dec 0))  ; 直接回车时设为默认值0
    (t (setq dec (atoi input)))  ; 非空输入转为整数
  )
  
  ;;; 确保小数位数为非负整数
  (if (< dec 0) (setq dec 0))  ; 负数自动归零

  ;;; 主执行逻辑
  (if (setq ss (ssget '((0 . "DIMENSION"))))  ; 成功选择标注时
    (progn
      (setvar 'DIMDEC dec)  ; 动态设置小数位数
      (command "_.dimstyle" "_apply" ss "")  ; 更新标注样式
    )
    (princ "\n未选中标注对象！")  ; 选择失败提示
  )
  (princ)  ; 静默退出
)

;插入文字"手工下料"
(defun c:wz1 (/  BL2 PT2)
	(setvar "cmdecho" 0)	
      	(setq BL2 1)
	(setq PT2 (getpoint "\n选择插入点"))
(while PT2
        (COMMAND "COLOR" 7)
	(command "text" "m" PT2 300 0 "手工下料")	
	(setq PT2 (getpoint "\n选择插入点"))
        
)
(princ)
)

;插入文字"SUS304 1.5T"
(defun c:wz2 (/  BL2 PT2)
	(setvar "cmdecho" 0)	
      	(setq BL2 1)
	(setq PT2 (getpoint "\n选择插入点"))
(while PT2
        (COMMAND "COLOR" 6)
	(command "text" "m" PT2 1500 0 "SUS304 1.5T")	
	(setq PT2 (getpoint "\n选择插入点"))
        (COMMAND "COLOR" 7)
)
(princ)
)
;插入文字"2"
(defun c:wz3 (/  BL2 PT2)
	(setvar "cmdecho" 0)	
      	(setq BL2 1)
	(setq PT2 (getpoint "\n选择插入点"))
(while PT2
        (COMMAND "COLOR" 4)
	(command "text" "m" PT2 150 0 "2")	
	(setq PT2 (getpoint "\n选择插入点"))
  (COMMAND "COLOR" 7)
)
(princ)
)
;插入文字"所有主管开口切割时请保持微连接！"
(defun c:wz4 (/  BL2 PT2)
	(setvar "cmdecho" 0)	
      	(setq BL2 1)
	(setq PT2 (getpoint "\n选择插入点"))
(while PT2
        (COMMAND "COLOR" 7)
	(command "text" "m" PT2 300 0 "所有主管开口切割时请保持微连接！")	
	(setq PT2 (getpoint "\n选择插入点"))
        
)
(princ)
)

;切换标注图层到"m-5""m-8" "m-10"  "m-15"
(defun c:11(/ )
  (command "-dimstyle" "r" "m-5")
)
(defun c:22(/ )
  (command "-dimstyle" "r" "m-8")
)
(defun c:33(/ )
  (command "-dimstyle" "r" "m-10")
)
(defun c:44(/ )
  (command "-dimstyle" "r" "m-15")
)
;将标注修改到当前样式
(defun c:12 (/ p)
(setvar "cmdecho" 0)
(princ "\n选择需修改的标注 :")
(setq p (ssget))
(command "dim" "up" p "" "e") 
(setvar "cmdecho" 1)
)

;将选中文字扩大一倍
(defun C:w1 ( / s n ename obj oldHeight newHeight) ; 新增变量存储高度值
  (setq s (ssget '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>")))) ; 选择文字对象
  (if s
    (progn
      (repeat (setq n (sslength s)) ; 遍历选择集
        (setq ename (ssname s (setq n (1- n))) ; 获取图元名
              obj (vlax-ename->vla-object ename) ; 转换为VLA对象
              oldHeight (vla-get-Height obj) ; 获取原文字高度[1,5](@ref)
              newHeight (* oldHeight 2.0) ; 计算新高度（扩大一倍）
        )
        (vla-put-Height obj newHeight) ; 设置新高度
      )
      (princ (strcat "\n已修改 " (itoa (sslength s)) " 个文字对象")) ; 操作反馈
    )
    (princ "\n未选中文字对象！") ; 空选择集提示
  )
  (princ)
)
;将选中的文字缩小一倍
(defun C:w2 ( / s n ename obj oldHeight newHeight) ; 新增变量存储高度值
  (setq s (ssget '((-4 . "<OR") (0 . "MTEXT") (0 . "TEXT") (-4 . "OR>")))) ; 选择文字对象
  (if s
    (progn
      (repeat (setq n (sslength s)) ; 遍历选择集
        (setq ename (ssname s (setq n (1- n))) ; 获取图元名
              obj (vlax-ename->vla-object ename) ; 转换为VLA对象
              oldHeight (vla-get-Height obj) ; 获取原文字高度[1,5](@ref)
              newHeight (/ oldHeight 2.0) ; 计算新高度（扩大一倍）
        )
        (vla-put-Height obj newHeight) ; 设置新高度
      )
      (princ (strcat "\n已修改 " (itoa (sslength s)) " 个文字对象")) ; 操作反馈
    )
    (princ "\n未选中文字对象！") ; 空选择集提示
  )
  (princ)
)

;贴边马口开洞
(defun c:c3a(/ d1 d2 pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11  )
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
   (command "._undo" "_begin")
(setq d1(getreal "开口贴边长<597>"))
(if (not d1) (setq d1 597))
(setq d2(getreal "开口贴边宽<597>"))
(if (not d2) (setq d2 597))
(setq pt0(getpoint "插入点"))
;上面的为需要的固定参数
;编程开始
(setq p1(list (car pt0) (+ (cadr pt0) d2))
      p2(list (+ (car p1) 0.2) (+ (cadr p1) 0.0))
      p3(list (car p2) (- (cadr p2) 0.5))
      p4(list (+ (car p3) (- d1 0.4)) (cadr p3))
      p5(list (car p4) (+ (cadr p4) 0.5))
      p6(list (+ (car p5) 0.2) (cadr p5))
      p7(list (car p6) (cadr pt0))
      p8(list (- (car p7) 0.2) (cadr p7))
      p9(list (car p8) (+ (cadr p8) 0.5))
      p10(list (car p3) (cadr p9))
      p11(list (car p10) (- (cadr p10) 0.5)))
(MK-line (list pt0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11))  
  
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;德国项目支架
(defun c:c3b(/ d4 d5 make_dgzj_dcl p1 p10 p11 p1a p2 p2a p3 p3a p4 p4a p5 p5a p6 p6a p7 p8 p9 pt0) ;德国支架绘制
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode" 0)  ;关闭对象捕捉状态
	(defun make_DGZJ_dcl (/ lst_str str file f)
  (setq lst_str
        (list
	 "德国项目支架:dialog { //定义名字为德国项目支架的对话框"
 "     label= \"德国项目支架\";//显示在对话框顶部的标签"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"序号          (个)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d0\";//编辑框1的关键字"
  "               mnemonic = \"d0\";//编辑框1的热键"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"支架数量      (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d1\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

   "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"支架长        (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d2\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

  "     :row{ //引用行"
  "           :edit_box{ //引用编辑框1"
  "               label=\"保温厚度     (mm)：\"; //编辑框1的标签"
  "               edit_width=8; //编辑框1的宽度"
  "               key= \"d3\";//编辑框1的关键字"
  "            }} //编辑框1引用结束"

             "     ok_cancel;// 引用ok_cancel组合控件"
             "}"
       )
  )
  (setq file (vl-filename-mktemp "DclTemp-DGZJ.dcl"))
  (setq fff (open file "w"))
  (foreach str lst_str
      (write-line str fff)
  )
  (close fff)
  file
)
   (command "._undo" "_begin")
  (setq Keys '("d0" "d1" "d2" "d3"))
  (if (not c3bd0)
  (progn
  (setq c3bd0 1 c3bd1 2)
  (setq c3bd2 600 c3bd3 80);设变量初值
  ))
  
    ;加载DCL对话框
    (setq DcLwjm (make_DGZJ_dcl))      ;生成DCL对话框
    (setq dcl_id (load_dialog DcLwjm)) ;加载DCL对话框

    ;激活DCL画面
    (if (not (new_dialog "德国项目支架" dcl_id))
        (exit)
    )

    ;控件赋初值
    (mapcar '(lambda(Key Val) (set_tile Key Val))
             Keys
             (list (rtos c3bd0 2 2)
                   (rtos c3bd1 2 2)  (rtos c3bd2 2 2)
		   (rtos c3bd3 2 2) 

		   )
    )
    ;设置d1为焦点
    (mode_tile "d0" 2)

    ;控件相关操作
    (foreach Key Keys
        (action_tile Key "(set (read (strcat \"c3b\" $key)) (atof (get_tile $key)))
                          
                          "
        )
    )
  
    (action_tile "accept" "(done_dialog 1)")

    ;将控制权交给DCL
    (setq do_what (start_dialog))

    ;终止DCL: (done_dialog 0) (done_dialog 1)
    (cond ((= do_what 0)
              (princ "\n单击了取消按钮")
          )
          ((= do_what 1)
              (princ "\n单击了确定按钮")
              ; 这里加入进行相应的处理部分
 (setq pt0(getpoint"请点击插入的位置:"))
  (if (= c3bd3 80)
    (progn
    (setq d4 53)
    (setq d5 28))
    
    (progn
    (if (= c3bd3 100)
      (progn
     (setq d5 28)
    (setq d4 73))
      (progn
     (setq d5 13)
     (setq d4 23)))))

(setq p1(list (car pt0) (+ (cadr pt0) d4))
      p2(list (car p1) (+ (cadr p1) 196))
      p3(list (car p2) (+ (cadr p2) d4))
      p4(list (+ (car p3) c3bd2 90) (cadr p3))
      p5(list (car p4) (cadr p2))
      p6(list (+ (car p5) d5) (cadr p5))
      p7(list (car p6) (cadr p1))
      p8(list (car p5) (cadr p1))
      p9(list (car p4) (cadr pt0)))
 (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
 (cons 90 4) (cons 10 p8) (cons 10 p9)(cons 10 pt0)(cons 10 p1)))
   (command "fillet" "r" 3)
   (command "fillet" "p" (entlast));倒R5圆角		   
	   
 (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
 (cons 90 4) (cons 10 p2) (cons 10 p3)(cons 10 p4)(cons 10 p5)))
   (command "fillet" "r" 3)
   (command "fillet" "p" (entlast));倒R5圆角		   	   
	   
  (command "line" p1 p2  "")
  (command "line" p5 p6 p7 p8  "")	   

	   
  (setq p1a(list (+ (car p1) 1) ( cadr p1))
      p2a(list (+ (car p2) 1) ( cadr p2))
      p3a(list (- (car p5) 1) ( cadr p5))
      p4a(list (car p5) (- ( cadr p5) 1))
      p5a(list (- (car p8) 1) ( cadr p8))
      p6a(list (car p8) (+ ( cadr p8) 1)))
  (command "color" 2)
  (command "line" p1 p1a "")
  (command "line" p2 p2a "")
  (command "line" p5 p3a "")
  (command "line" p5 p4a "")
  (command "line" p8 p5a "")
  (command "line" p8 p6a "")
  (command "color" 7)
  (command "-DIMSTYLE" "R" "m-5")
  (setvar "dimtix" 1) ;强制尺寸文本在两尺寸界线之内
  (command "dimlinear" pt0 p1 "@-50,50")
  (command "dimlinear" p1 p2 "@-50,50")
  (command "dimlinear" p2 p3 "@-50,50")
  (command "-DIMSTYLE" "R" "m-15")
  (command "dimlinear" p3 p4 "@-100,100")
  (setq p10(list (+ (car p3) (/ (+ c3bd2 90) 2)) (+ (cadr p1) 98)))
  (setq p11(list (+ (car p10) 250) (cadr p10)))
  (command "color" 1)
  (setq c3bd0s(rtos c3bd0 2 2))
  (command "text" "m" p10 200 0  c3bd0s)
  (command "color" 4)
  (if (/= c3bd1 1)
  (command "text" "m" p11 100 0  c3bd1))
  (command "color" 7)
  (command "color" "red")
  (command "layer" "S" "3中心线层" "")
  (command "line" p2 p5 "")(command "line" p1 p8 "");绘制中心线
    (command "color" "byblock")
  (command "layer" "S" "1轮廓层" "")))
  (setvar "osmode" 16383)  ;打开对象捕捉状态
  (princ) ;静默退出
  (command "._undo" "_end")
  )

;选择所有的点
(defun c:xd(/ )
(sssetfirst'nil(ssget '((0 . "point"))))
  (princ)
)
;CAD合并插件
(defun c:xco (/ pt desktop pf path aa i pp fullpath)
  (setvar "CMDECHO" 0)
  (setq pt (list 0 0))
  
  ;; 获取桌面路径（兼容不同Windows版本）
  (setq desktop
    (strcat (getenv "USERPROFILE") "\\Desktop\\")  ; 最终回退到空字符串
  )

  ;; 显示文件选择对话框（默认定位到桌面）
  (setq pf 
    (getfiled "请选择目录里任意一个DXF文件 (程序将自动处理同目录所有DXF)" 
              desktop ; 默认路径和文件类型
              "dxf" 
              0)
  )  
  (if (not pf)
    (progn
      (princ "\n用户取消操作")
      (exit)
    )
  )
  
  ;; 获取文件目录
  (setq path (vl-filename-directory pf))
  (setq path (strcat path "\\"))
  (setq aa (vl-directory-files path "*.dxf" 1))
  
  ;; 如果没有找到文件
  (if (not aa)
    (progn
      (alert (strcat "未找到DXF文件: " path))
      (exit)
    )
  )
  
  (setq i 0)
	(setq pt0 (getpoint "\n请选择合并文件插入的基点: "))
  (prompt "\n程序正在处理中，请等待...")
  (setq col 0     ; 列计数器
        row 0     ; 行计数器
        pt (list (car pt0) (cadr pt0))) ; 当前插入点
  (while (setq pp (nth i aa))
    (setq fullpath (strcat path pp))
    (if (findfile fullpath)
      (progn
				(command "_.-insert" (strcat "*" fullpath)  pt "1" "")
        (setq pt (polar pt 0 8000)) ; 水平移动8000单位
				(setq col (1+ col))
        
        ;; 每6个文件换行
        (if (and (>= col 6) (zerop (rem col 6)))
          (progn
            (setq col 0
                  row (1+ row)
                  pt (list (car pt0) (- (cadr pt) 16000)) ; Y减少8000
            )
          )
        )    	
      )			
      (princ (strcat "\n文件不存在: " fullpath))
    )
    (setq i (1+ i))
  )
  (princ (strcat "\n处理完成! 共插入 " (itoa (length aa)) " 个DXF文件"))
  (princ)
)

(defun c:xco1 (/ pt desktop pf path aa i pp fullpath)
  (setvar "CMDECHO" 0)
  (setq pt (list 0 0))
  
  ;; 获取桌面路径（兼容不同Windows版本）
  (setq desktop
    (strcat (getenv "USERPROFILE") "\\Desktop\\")  ; 最终回退到空字符串
  )

  ;; 显示文件选择对话框（默认定位到桌面）
  (setq pf 
    (getfiled "请选择目录里任意一个Dwg文件 (程序将自动处理同目录所有dwg)" 
              desktop ; 默认路径和文件类型
              "dwg" 
              0)
  )  
  (if (not pf)
    (progn
      (princ "\n用户取消操作")
      (exit)
    )
  )
  
  ;; 获取文件目录
  (setq path (vl-filename-directory pf))
  (setq path (strcat path "\\"))
  (setq aa (vl-directory-files path "*.dwg" 1))
  
  ;; 如果没有找到文件
  (if (not aa)
    (progn
      (alert (strcat "未找到DWG文件: " path))
      (exit)
    )
  )
  
  (setq i 0)
	(setq pt0 (getpoint "\n请选择合并文件插入的基点: "))
  (prompt "\n程序正在处理中，请等待...")
  (setq col 0     ; 列计数器
        row 0     ; 行计数器
        pt (list (car pt0) (cadr pt0))) ; 当前插入点
  (while (setq pp (nth i aa))
    (setq fullpath (strcat path pp))
    (if (findfile fullpath)
      (progn
				(command "_.-insert" (strcat "*" fullpath)  pt "1" "")
        (setq pt (polar pt 0 8000)) ; 水平移动8000单位
				(setq col (1+ col))
        
        ;; 每6个文件换行
        (if (and (>= col 6) (zerop (rem col 6)))
          (progn
            (setq col 0
                  row (1+ row)
                  pt (list (car pt0) (- (cadr pt) 16000)) ; Y减少8000
            )
          )
        )    	
      )			
      (princ (strcat "\n文件不存在: " fullpath))
    )
    (setq i (1+ i))
  )
  (princ (strcat "\n处理完成! 共插入 " (itoa (length aa)) " 个DWG文件"))
  (princ)
)

;弯头增直扣R快算
(defun c:c5b(/ c5b c5bd0 c5bd1 c5bd2 dcl_file dcl_id getdata1 make-dclcs re)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "弯头扣R加直快算:dialog"
				 "{ // start dcl"
				 "label = \"弯头扣R加直快算\";"	
         ":row{"
         ":boxed_column{label = \"交互参数\";"			 
				 ":edit_box{label=\"弯头角度 :\";key=\"d0\";edit_width=5;}";编辑框
				 ":edit_box{label=\"增加直段 :\";key=\"d1\";edit_width=5;}";编辑框
				 ":edit_box{label=\"原始内R  :\";key=\"d2\";edit_width=5;}}}";编辑框
				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun c5b (/ c5bd4)
		(defun write-to-clipboard (data / html result)
  (vl-load-com)
  (setq html (vlax-create-object "htmlfile"))
  (setq result
    (vl-catch-all-apply
      '(lambda ()
        (vlax-invoke
          (vlax-get (vlax-get html 'parentWindow) 'clipboardData)
          'setData "Text" (vl-princ-to-string data))
        )
      )
  )
  (vlax-release-object html)
  (if (vl-catch-all-error-p result)
    (prompt "\n无法写入剪切板!")
    (prompt "\n数据已复制到剪切板!")
  )
)
    (setq c5bd4
			(- c5bd2
        (/ c5bd1
					(tan
						(* (/ c5bd0 2.0)      ; 计算 θ/2 (角度值)
							(/ pi 180.0)       ; 角度转弧度系数
						)
					)
        )
			)
		);δR = c5bd1 / tan(θ/2)
		(write-to-clipboard c5bd4)
		(alert (strcat "扣除后的内R为 " (rtos c5bd4 2 2)))
		
		(princ  c5bd4)
		(setvar "osmode" 16383)  ;打开对象捕捉状态
		(command "._undo" "_end")	
	)
	;;---------开始写面板调用函数
	(if (not c5bd0)
		(progn (setq c5bd0 45)			
      (setq c5bd1 50)(setq c5bd2 500)
		))
	
	(h-read1  "c5b");读取注册表的数据
	(defun getdata1()
		(setq 
			c5bd0 (atof (get_tile "d0"))
			c5bd1 (atof (get_tile "d1"))
			c5bd2 (atof (get_tile "d2"))
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "弯头扣R加直快算" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
  (set_tile "d0" (rtos c5bd0 2 2));
  (set_tile "d1" (rtos c5bd1 2 2))
  (set_tile "d2" (rtos c5bd2 2 2));
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消计算！")))
		((= re 2);帮助
			(progn
				(alert "按照上面的数据填就行了
程序会自动将计算的数据写入剪切板")	
			))	
		
		((= re 1);确认
			(progn
				(c5b)
				
			))	
	)	
	
	(h-save1  '(c5bd0 c5bd1 c5bd2) "c5b");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)

;文字查重
(defun c:fz (/ *error* ss dict dupList dupFound msg ent data content insPt height radius oldEcho i entry entities tbox centerPt dupMinPt dupMaxPt margin count)
    ; 错误处理函数
    (defun *error* (msg)
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\n错误: " msg))
        )
        (setvar "CMDECHO" oldEcho)
        (princ)
    )
    
    (setq oldEcho (getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    
    ; 选择单行文字
    (if (not (setq ss (ssget '((0 . "TEXT")))))
        (progn
            (alert "未选择文字对象")
            (exit)
        )
    )
    
    (setq dict '()
          dupList '()
          dupFound nil
    )
    
    ; 收集文字数据到字典
    (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))))
        (setq data (entget ent))
        (setq content (cdr (assoc 1 data)))
        
        ; 添加到字典 (内容 -> 实体列表)
        (if (setq entry (assoc content dict))
            (progn
                ; 如果内容已存在，添加到实体列表
                (setq dict (subst (cons content (cons ent (cdr entry))) entry dict))
                (if (not (member content dupList))
                    (setq dupList (cons content dupList))
                )
                (setq dupFound t)
            )
            ; 新内容，创建新条目
            (setq dict (cons (list content ent) dict))
        )
    )
    
    ; 处理重复文字
    (if dupFound
        (progn
            ; 初始化重复文字包围框
            (setq dupMinPt (list 1e308 1e308)
                  dupMaxPt (list -1e308 -1e308))
            
            ; 遍历所有重复内容
            (foreach content dupList
                ; 获取该内容的所有实体
                (setq entities (cdr (assoc content dict)))
                (setq count (length entities))  ; 获取重复数量
                
                ; 遍历每个重复实体
                (foreach ent entities
                    (setq data (entget ent))
                    (setq insPt (cdr (assoc 10 data)))
                    (setq height (cdr (assoc 40 data)))
                    
                    ; 计算文字中心点（使用文字包围盒）
                    (setq tbox (textbox (list (assoc 1 data) (assoc 40 data) (assoc 7 data) (assoc 72 data) (assoc 73 data))))
                    (if tbox
                        (progn
                            (setq centerPt (mapcar '/ (mapcar '+ (car tbox) (cadr tbox)) '(2.0 2.0)))
                            (setq centerPt (list (+ (car insPt) (car centerPt)) 
                                                (+ (cadr insPt) (cadr centerPt))))
                        )
                        ; 如果无法计算包围盒，使用插入点
                        (setq centerPt insPt)
                    )
                    
                    ; 计算半径（文字高度的2倍）
                    (setq radius (* height 2.0))
                    
                    ; 绘制红色圆圈
                    (entmake (list
                        '(0 . "CIRCLE")
                        (cons 10 centerPt)  ; 使用文字中心点
                        (cons 40 radius)
                        (cons 62 2)        ; 黄色
												(cons 8 "序号图层")
                    ))
                    
                    ; 更新重复文字包围框
                    (setq dupMinPt (list (min (car dupMinPt) (- (car centerPt) radius)) 
                                         (min (cadr dupMinPt) (- (cadr centerPt) radius))))
                    (setq dupMaxPt (list (max (car dupMaxPt) (+ (car centerPt) radius)) 
                                         (max (cadr dupMaxPt) (+ (cadr centerPt) radius))))
                )
            )
            
            ; 缩放视图到重复文字区域
            (if (and dupMinPt dupMaxPt)
                (progn
                    ; 添加10%的边距
                    (setq margin (* (distance dupMinPt dupMaxPt) 0.1))
                    (setq dupMinPt (mapcar '- dupMinPt (list margin margin)))
                    (setq dupMaxPt (mapcar '+ dupMaxPt (list margin margin)))
                    
                    (command "_.zoom" "_window" dupMinPt dupMaxPt)
                )
            )
            
            ; 构建重复内容消息（带重复数量）
            (setq msg "以下文字内容重复:\n\n")
            (foreach content dupList
                (setq entities (cdr (assoc content dict)))
                (setq count (length entities))  ; 获取重复数量
                (setq msg (strcat msg "内容: \"" content "\" - 重复数量: " (itoa count) "\n"))
            )
            (setq msg (strcat msg "\n共发现 " (itoa (length dupList)) " 种重复文字"))
            (alert msg)
        )
        (alert "所有文字均无重复")
    )   
    (setvar "CMDECHO" oldEcho)
    (princ)
)


(defun c:y1(/ dcl_file dcl_id getdata1 make-dclcs pt0 re y1 y1d0 y1d1 y1d2 y1d3 y1d4 y1d5 y1d6 y1d7 y1d8)
	(command "._undo" "_begin")
  (setvar "cmdecho" 0) ;关闭普通命令提示信息
  (setvar "osmode"  0)  ;关闭对象捕捉状态
	(defun make-dclCS  (/ lst_str str file f);;dcl显示面板
		(setq lst_str
			'(
				 "圆弯头展开:dialog"
				 "{ // start dcl"
				 "label = \"圆弯头展开\";"	
         ":row{"
         ":boxed_column{label = \"交互参数\";"			 
				 ":edit_box{label=\"弯头序号:\";key=\"d0\";}";编辑框
				 ":edit_box{label=\"弯头直径:\";key=\"d1\";}";编辑框
				 ":edit_box{label=\"弯头内R :\";key=\"d2\";}";编辑框
				 ":edit_box{label=\"弯头角度:\";key=\"d3\";}";编辑框
				 ":edit_box{label=\"上伸量 :\";key=\"d4\";}";编辑框
				 ":edit_box{label=\"下伸量 :\";key=\"d5\";}}";编辑框
				 ":boxed_column{label = \"设置参数\";"
				 ":edit_box{label=\"板材厚度:\";key=\"d6\";is_tab_stop=false;}";编辑框
				 ":edit_box{label=\"板材分段:\";key=\"d7\";is_tab_stop=false;}";板材板厚
				 ":popup_list{label=\"展开形式:\";key=\"d8\";list=\"整体\\n单段\\n引弧\";is_tab_stop=false;}"
				 ":button  {label=\"读取数据批量生成\"; key = \"EL1\";is_tab_stop=false;}"
         ":spacer{height = 8;}}}";填补剩余间隙，使一二两列保持平行
				 
				 ":row{"":button{label=\"确定(&Q)\";key=\"accept\"; is_default=true;} ";行列表，确定
				 ":button{label=\"取消(&C)\";key=\"cancel\";is_tab_stop=false;is_cancel=true;}";取消按钮
				 ":button{label=\"说明(&S)\";key=\"help\";is_tab_stop=false;is_cancel=true;}""}}";说明按钮			
			 ))
		
		(setq file (vl-filename-mktemp "DclTemp.dcl"))
		(setq f (open file "w"))
		(foreach str lst_str
			(princ "\n" f)
			(princ str f)
		)
		(close f)
		;;返回
		file
	)
	(defun y1 (pt0 / a1 a2 am d1 d2 d3 d4 d5 da dr h h1 l l2 l3 p1 p2 p3 pt pt1 pt2 ptb pts ss x y1dd y1zt)
		(command "._undo" "_begin")
		(setvar "cmdecho" 0) ;关闭普通命令提示信息
		(setvar "osmode"  0)  ;关闭对象捕捉状态
		(setq d1 (- y1d1 y1d6);计算圆的中径
			    d2 (+ (/ d1 2)  y1d2);计算圆的中心R  	
			    a1 (/ y1d3 (* 2 (- y1d7 1)));计算端节角度
			    am (* 2 a1);计算中间节角度
			    ss 96;计算圆的周长分割成96等分的精度
			    d3 (/ (* d1 pi) ss);计算圆的周长分割成48等分的单份长度
			    d4 y1d4;上伸量
			    d5 y1d5;下伸量
			    dr (/  d1  2)
          a2 (/ 360.0 ss));计算圆的周长分割成48等分的单份长度				
	 ;端节任一素线长ln=tana1(R+-r2sinBn) a1为端节角度 R为弯头中径，Bn为圆周各
   ;等分点与同一直径的夹角,假设设置为48等分，那么1/4的角度就为12等分，单个角度为90除以12度
 (setq H (+ (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* 0 a2))))) (* 2 (- y1d7 1))) d4 d5));所有等分的总长
 (setq H1(* (tan (ang a1)) (+ d2 (* dr (sin (ang (* 0 a2))))) 2));中间段的长度
 (setq L(* d1 pi));计算圆的周长
;-------------------------------------------------------------------------------------------------------------------
		(setq p1 (aa pt0 0 h)
	     p2 (aa p1 l 0)
	     p3 (aB  p2  PT0 0 0))
;绘制展开图	

(defun y1zt (/ l1 n pt x);弯头整体展开图
(text  (strcat y1d0 "/1") (list (car (h-mid p1 p2)) (cadr (h-mid pt0 p1))) 100 1 1 "0" ) 
(MK-line (list pt0 p1 p2 p3));绘制弯头外形框
(dim1 p1 p2 1 30 "m-8")(dim1 pt0 p1 2 -100 "m-8")
(dim1 (AA PT0 0 y1d5) pt0  2 -50 "m-8")(dim1 (AA P1 0 (* y1d4 -1) ) p1  2 -50 "m-8")
(setq x 0);定义总共需要绘制的弧线			
(repeat (- y1d7 1) 
			(if  (= x 0)
			(progn
				(setq n 0
					pt '())
				(repeat (+ ss 1 )
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d5));素线长度计算+弯头下伸量
					
					(setq pt (cons (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
						(progn
							(line1 (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1)) 4)
							(line1 (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1)) 3)
						))			
					(setq n  (1+ n)))							
				  (mk-line2  pt 2);绘制端节
			)					
			(progn
				(setq n 0
					pt '())
				(repeat (+ ss 1 )
					(if (/= (rem x 2) 0);判断X的奇偶性
          (setq L1 (+ (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2)))))) d5));为奇数对L1的定义
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d5));为偶数对L1的定义	
					)
				(setq pt (cons (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1 (* x h1))) pt))	
					
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
						(progn
							(line1 (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1 (* x h1))) 4)
							(line1 (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1 (* x h1))) 3)
						))			
					(setq n  (1+ n)))									
				(mk-line2  pt 2);绘制中间节		
				))	
		(setq x (1+ x)))
)	
(defun y1dd (/ l1 l3 m1 n pt pt-b pt-bottom pts pt-t pt-top x x1);弯头单段展开图
(setq x 0);定义总共需要绘制的弧线
(setq m1 1);定义序号开始阶段数字
(repeat y1d7 
			(cond  
			((= x 0)
				(setq n 0
					pt  (list pt0))
				(repeat (+ ss 1 )
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d5));素线长度计算+弯头下伸量					
					(setq pt (cons (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
              (progn
							(line1 (list (+ (car pt0) (* n d3)) (+ (cadr pt0) L1)) 4)	
							(if(= n (* (/ ss 4) 3))
								(progn
								(text (strcat y1d0 "/" (rtos m1)) (list (+ (car pt0) (* n d3)) (+ (cadr pt0) (/ L1 2))) (/ L1 2) 1 1 "0")
							  (setq m1 (1+ m1))))
							))											
					(setq n  (1+ n)))
       (setq pt(cons (list (+ (car pt0) (* d1 pi)) (cadr pt0)) pt))				
				  (mk-line  pt);绘制端节
			(dim1 (AA pt0 0 Y1D5) pt0  2 -80 "m-8")
			)
      ((and (/= x 0) (/= x (- y1d7 1)))
				 (setq L3 (* (* (tan (ang a1)) (- d2 (* dr (sin (ang (* (* (/ ss 4) 3) a2)))))) 2));最高点
				(setq n 0
					pts (list (car pt0) (+ (cadr pt0)  (+ (* L3 X ) (/ L3 2 ))))
      pt-top '()    ; 上轮廓点列表
      pt-bottom '() ; 下轮廓点列表
)
(repeat (+ ss 1 ) 
  (progn
    (setq L1 (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2)))))));素线长度计算
		
		(if (/= (rem x 2) 0);判断X的奇偶性
			(progn (setq x1 1)
			(setq L1 (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2))))))));素线长度计算
			(progn (setq x1 2)
      (setq L1 (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2))))))));素线长度计算
			
					)
		
    (setq pt-t (list (+ (car pts) (* n d3)) (+ (cadr pts) L1)));上侧素线长度
    (setq pt-b (list (+ (car pts) (* n d3)) (- (cadr pts) L1)));下侧素线长度
       
    ; 分别添加到上下轮廓列表
    (setq pt-top (cons pt-t pt-top))
    (setq pt-bottom (cons pt-b pt-bottom))  
    (if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3))) 
      (progn 
        (line1 pt-t 4)(line1 pt-b 3)
				(cond ((and (= x1 1)(= n (/ ss 4)))
	(text (strcat y1d0 "/" (rtos m1)) (list (+ (car pts) (* (/ ss 4) d3)) (cadr pts)) (/ L1 2) 1 1 "0")
	(setq m1 (1+ m1)))
					((and (= x1 2)(= n (* (/ ss 4) 3)))
	(text (strcat y1d0 "/" (rtos m1)) (list (+ (car pts) (* (* (/ ss 4) 3) d3)) (cadr pts)) (/ L1 2) 1 1 "0")
	(setq m1 (1+ m1)))
							)
				)								
        )  
    (setq n (1+ n))
  ))
; 构建正确的点顺序：先上轮廓从左到右，然后下轮廓从右到左
(setq pt (append  pt-top (reverse pt-bottom)))				
(mk-line pt) ; 中间节				
	)
	((= x (- y1d7 1))
				(setq n 0
					L3 (* (* (tan (ang a1)) (- d2 (* dr (sin (ang (* (* (/ ss 4) 3) a2)))))) 2);最高点
					pts (list (car pt0) (+ (cadr pt0)  (+ (* L3 X ) l3)))
					pt  (list pts))
				(repeat (+ ss 1) 
					
					(if (/= (rem x 2) 0);判断X的奇偶性
			(progn (setq x1 1)
			(setq L1 (+ (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2)))))) d4))
			(if(= n (/ ss 4))
								(progn
								(text (strcat y1d0 "/" (rtos m1)) (list (+ (car pts) (* n d3)) (- (cadr pts) (/ L1 2))) (/ L1 2) 1 1 "0")
							  (setq m1 (1+ m1))))
			);素线长度计算
						
			(progn (setq x1 2)
				
      (setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d4));素线长度计算		
			(if(= n (* (/ ss 4) 3))
								(progn
								(text (strcat y1d0 "/" (rtos m1)) (list (+ (car pts) (* n d3)) (- (cadr pts) (/ L1 2))) (/ L1 2) 1 1 "0")
							  (setq m1 (1+ m1))))			
					))
					
					(setq pt (cons (list (+ (car pts) (* n d3)) (- (cadr pts) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
            (progn
	        						
							(line1 (list (+ (car pts) (* n d3)) (- (cadr pts) L1)) 3)))																
					(setq n  (1+ n)))
       (setq pt(cons (list (+ (car pts) (* d1 pi)) (cadr pts)) pt))				
				  (mk-line  pt);绘制上端节
		    (dim1 (AA ptS 0 (* Y1D4 -1)) ptS  2 -80 "m-8")
			))	
			(setq x  (1+ x))	
			)			
			
		

	
	
	
	
)		

(defun y1yh(/ l1 n p1 pt pt1 pt2 pt3 x);弯头引弧展开	
(setq x 0);定义总共需要绘制的弧线		
	  (setq pt1 (aa pt0 0 h)
		pt2 (aa pt1 l 0)
		pt3 (aB  pt2  PT0 0 0));四角定位
(MK-line1 (list pt0 pt1)) (MK-line1 (list pt2 pt3))	
(setq p1  (AA PT1 0 (* (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* 0 a2)))))) d5) -1)))
(dim1 p1 (AA P1 0 Y1D5) 2 -50 "m-8")	(dim1 p1 (AA P1 0 (* Y1D4 -1)) 2 -50 "m-8")
(setq n 0
					pt  '())
				(repeat (+ ss 1)
					(if (/= (rem y1d7 2) 0);判断X的奇偶性
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d5));为奇数对L1的定义
					(setq L1 (+ (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2)))))) d5));为偶数对L1的定义
					)
					(setq pt (cons (list (+ (car p1) (* n d3)) (+ (cadr p1) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
              (progn
							(line1 (list (+ (car p1) (* n d3)) (+ (cadr p1) L1)) 4)								
							))											
					(setq n  (1+ n)))			
				  (mk-line1  pt);绘制端节			
	        (mk-line2 (LIST P1 (list (+ (car p1) (* d1 pi)) (cadr p1))) 2);绘制端节	
(if (/= y1d7 2)
	(progn 
	(setq n 0
					pt  '())
				(repeat (+ ss 1 )
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d4));素线长度计算+弯头下伸量					
					(setq pt (cons (list (+ (car p1) (* n d3)) (- (cadr p1) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
              (progn
							(line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1)) 4)	
	            (line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1)) 3)							
							))											
					(setq n  (1+ n)))     				
				  (mk-line2  pt 2);绘制端节	
	)
	(progn 
	(setq n 0
					pt  '())
				(repeat (+ ss 1 )
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d4));素线长度计算+弯头下伸量					
					(setq pt (cons (list (+ (car p1) (* n d3)) (- (cadr p1) L1)) pt))
					(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)));当定位点在最高点与最低点的时候刻线
              (progn	
	            (line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1)) 3)							
							))											
					(setq n  (1+ n)))     				
				  (mk-line1  pt );绘制端节	
	))

	
(setq x 1)	
(repeat (- y1d7 2) 	
				(setq n 0
					pt '())
				(repeat (+ ss 1 )
					(if (/= (rem x 2) 0);判断X的奇偶性
          (setq L1 (+ (* (tan (ang a1)) (+ d2 (* dr (sin (ang (* n a2)))))) d4));为奇数对L1的定义					
					(setq L1 (+ (* (tan (ang a1)) (- d2 (* dr (sin (ang (* n a2)))))) d4));为偶数对L1的定义	
					)
					(setq pt (cons (list (+ (car p1) (* n d3)) (- (cadr p1) L1 (* x h1))) pt))
					(if (/= x (- y1d7 2))
						(progn 
							(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)))  ;当定位点在最高点与最低点的时候刻线
								(progn
									(line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1(* x h1))) 4)
									(line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1(* x h1))) 3)
								)))	
						
						(progn 
							(if (or (= n (/ ss 4)) (= n (* (/ ss 4) 3)))  ;当定位点在最高点与最低点的时候刻线
								(progn
									(line1 (list (+ (car p1) (* n d3)) (- (cadr p1) L1(* x h1))) 3)
								))
						))								
					(setq n  (1+ n)))
	    (if (/= x (- y1d7 2))
				(mk-line2  pt 2)
				(mk-line1  pt )				
				)		
	(setq x (1+ x))
)							
(text  (strcat y1d0 "/1") (list (car (h-mid pt0 pt3)) (cadr (h-mid pt0 pt1))) 150 1 1 "0" )				  	
			)	
	
	
	
	
	
(cond 
	((= y1d8 0)
	(y1zt))
	((= y1d8 1)	
	(y1dd))	
  ((= y1d8 2)	
	(y1yh))
)		
		
		
		
;-------------------------------------------------------------------------------------------------------------------
;绘制模拟图形
(setq L2 (* (* (tan (ang a1)) (- d2 (* dr (sin (ang (* (/ ss 4) a2)))))) 2));最低点
(setq L3 (* (* (tan (ang a1)) (- d2 (* dr (sin (ang (* (* (/ ss 4) 3) a2)))))) 2));最高点
(setq da (/ y1d3 (- y1d7 1)));计算单个中间节的角度		
(setq pt1 (AA P3 800 0))
(setq x 0)
(setq pt (list pt1))
(setq pt2 (list(AA PT1 (- Y1D1 y1d6) 0))	)	
(repeat 
  y1d7
		(cond ((= x 0)
		(setq pt (cons (polar pt1 (/ pi 2)  (+ (/ L3 2) Y1D5)) pt))
		(setq pt2 (cons (polar (AA PT1 (- Y1D1 y1d6) 0) (/ pi 2)  (+ (/ L2 2) Y1D5)) pt2))				
					)				
		     ((= x (- y1d7 1))
		(setq pts (car pt)) 
		(setq pt (cons (polar pts (-(/ pi 2) (ang (* x da) ))  (+ (/ L3 2) Y1D4)) pt))
		(setq ptb (car pt2))			 
		(setq pt2 (cons (polar ptb (-(/ pi 2) (ang (* x da) ))  (+ (/ L2 2) Y1D4)) pt2))			 					 
				 )
			
    ((and (/= x (- y1d7 1)) (/= x 0))	
		(setq pts (car pt))	
		(setq pt (cons (polar pts (-(/ pi 2) (ang (* x da) ))  l3) pt))
		(setq ptb (car pt2))	
		(setq pt2 (cons (polar ptb (-(/ pi 2) (ang (* x da) ))  l2) pt2))				
		)		
		)	
(setq x (1+ x)))	
		(mapcar '(lambda (pt1 pt2)(MK-line3 (list pt1 pt2)  7 "序号图层"))							 					 
              pt pt2 )
(MK-line3 pt 7 "序号图层")(MK-line3 pt2 7 "序号图层")		
(dim1  (AA PT1 0 y1d5 ) pt1  2  -120 "m-8");标注下伸量
(dal (polar (car pt) (angle (car pt) (cadr pt) )   y1d4) (car pt) (list (- (car(car pt)) 50)  (cadr(car pt))));标注上伸量
(dim1 (AA PT1 Y1D1 0) (AA PT1 (+ Y1D1 y1d2) 0) 1 -120 "m-8" )		
(entmod (subst (cons 1 "R <>") (assoc 1 (entget (entlast))) (entget (entlast))))				
(dim1  pt1 (AA PT1 Y1D1 0) 1  -120 "m-8")	
(entmod (subst (cons 1 "%%c<>") (assoc 1 (entget (entlast))) (entget (entlast))))			
(text "辅助视图" (AA PT1 (/ y1d1 2) -600)  150 7 1 "序号图层")
	

		
;-------------------------------------------------------------------------------------------------------------------
;绘制检查数据文字
(text (strcat "弯头直径为" (rtos y1d1)) (AA PT0 0 -600) 150 7 0 "序号图层")		
(text (strcat "弯头内R 为" (rtos y1d2)) (AA PT0 0 -900) 150 7 0 "序号图层")
(text (strcat "弯头角度为" (rtos y1d3)) (AA PT0 0 -1200) 150 7 0 "序号图层")
(text (strcat "弯头上伸量" (rtos y1d4)) (AA PT0 0 -1500) 150 7 0 "序号图层")
(text (strcat "弯头下伸量" (rtos y1d5)) (AA PT0 0 -1800) 150 7 0 "序号图层")
(text (strcat "弯头厚度为" (rtos y1d6)) (AA PT0 0 -2100) 150 7 0 "序号图层")
(text (strcat "弯头分段数" (rtos y1d7)"段") (AA PT0 0 -2400) 150 7 0 "序号图层")		
(cond ((or (and(>= y1d3 90) (>= y1d1 1000) (<= y1d7 4))
				 (and  (<= y1d3 30)  (>= y1d7 3))
				 (and(<= y1d3 45)  (>= y1d7 4))
				 (and(> y1d3 60)  (<= y1d7 3))
				 )
(text "请注意，您的分段可能不合适！" (AA PT0 0 -2700) 150 1 0 "序号图层")	
	
	
	
			))		
		
		(setvar "osmode" 16383)  ;打开对象捕捉状态
		(command "._undo" "_end")	
	)

	(defun test1 (/ *excel* *sheet* *xlapp*  exname pcs pcs1 pt0)
  (vl-load-com)
  ;(setq exname "C:\\Users\\Administrator\\Desktop\\自动生成参数1.xlsx")
	(setq exname "D:\\小辉插件\\标准模板\\自动化生成数据表.xls")
  (setq *excel* (vlax-create-object "excel.application"))
  (setq *xlapp* (vlax-invoke-method (vlax-get-property *excel* 'Workbooks) 'Open exname))
  (vla-put-visible *excel* 0)  ;;显示工作表
  (setq *sheet* (vlax-get-property (vlax-get-property *xlapp* 'Worksheets) 'item "圆弯头"))
	(setq pcs (atof(Ljx-read-excel-text1 "J" 2 *sheet*)))
	(setq pt0(getpoint "请输入插入的位置："))
	(SETQ pcs1 1)
	    (while	
			
				(> pcs 0)
				(progn
				(setq pcs(- pcs 1))
				(SETQ pcs1(+ pcs1 1))
				(setq pt0 (list (+ (car pt0) 16000) (cadr pt0)))
			(setq	y1d0 (itoa(atoi(Ljx-read-excel-text1  "B" PCS1 *sheet*)))
				    y1d1 (atof(Ljx-read-excel-text1  "C" PCS1 *sheet*))
				    y1d2 (atof(Ljx-read-excel-text1  "D" PCS1 *sheet*))
				    y1d3 (atof(Ljx-read-excel-text1  "E" PCS1 *sheet*))
				    y1d4 (atof(Ljx-read-excel-text1  "F" PCS1 *sheet*))
				    y1d5 (atof(Ljx-read-excel-text1  "G" PCS1 *sheet*))
				    y1d6 (atof(Ljx-read-excel-text1  "H" PCS1 *sheet*))
			      y1d7 (atoi(Ljx-read-excel-text1  "I" PCS1 *sheet*))
				)
				(y1 pt0)	
			))   
  (vlax-invoke-method (vlax-get-property *excel* "ActiveWorkbook") 'Close 0)
  (vlax-invoke-method *excel* 'QUIT)
  (vlax-release-object *sheet*) 
  (vlax-release-object *xlapp*)
)
	
	
	
	
	
	
	(defun Ljx-read-excel-data1 (vv hor sh) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2))
)

;;;;;读取数excel数据函数输出text格式
(defun Ljx-read-excel-text1 (vv hor sh /  ru) ;;;vv为列数直接输入字母、hor为 第几行，直接输入数字,sh为工作表对象sheet
  (vl-princ-to-string (vlax-variant-value (vlax-get-property (vlax-get-property sh 'Range (strcat vv (itoa hor))) 'Value2)))
)
(defun ljx-vlxls-get-range-value1 ( sheet rangeid / range value valuelist )
  (setq range (vlax-get-property sheet 'Range rangeid))
  (setq value (vlax-get-property range 'Value2))
  (cond
    ((= (vlax-variant-type value)  8204);;;为数组时，即为区域;
        (progn
          (setq value (vlax-safearray->list(vlax-variant-value value)))
          (setq valuelist (mapcar (function (lambda (x) (mapcar 'vlax-variant-value x))) value))
        )
    )
    ( T;;;;为单个单元格;
      (setq valuelist (vlax-variant-value value))
    )
  );;;;cond
  valuelist
)	



	;;---------开始写面板调用函数
	(if (/= 'str (type y1d0))
		(progn (setq y1d0 "1")
			
      (setq y1d1 600)(setq y1d2 300)(setq y1d3 90)(setq y1d4 48.5)
			(setq y1d5 48.5)(setq y1d6 1.5)(setq y1d7 4)(setq y1d8 0)
		))
	
	(h-read1  "y1");读取注册表的数据
	(defun getdata1()
		(setq 
			y1d0 (get_tile "d0")
			y1d1 (atof (get_tile "d1"))
			y1d2 (atof (get_tile "d2"))
			y1d3 (atof (get_tile "d3"))
			y1d4 (atof (get_tile "d4"))
			y1d5 (atof (get_tile "d5"));分料数据
		  y1D6 (atof (get_tile "d6"));分料数据
			y1d7 (atoi (get_tile "d7"))
			y1d8 (atoi (get_tile "d8"))
		))
  (if (= (setq dcl_id (load_dialog (setq Dcl_File(make-dclCS)))) 0)(progn(alert "\n无法显示对话框！")(exit)))
	(if Dcl_File(vl-file-delete Dcl_File));加载后删除DCL文件
  (if(not (new_dialog "圆弯头展开" dcl_id))(progn(alert "\n无法显示对话框！")(exit)))
	
	(set_tile "d0" y1d0 );序号 ;将对应key的全局变量传递给控件，以便显示界面的时候直接显示上次记忆的控件key值
  (set_tile "d1" (rtos y1d1 2 2));
  (set_tile "d2" (rtos y1d2 2 2))
  (set_tile "d3" (rtos y1d3 2 2));
	(set_tile "d4" (rtos y1d4 2 2 ))
	(set_tile "d5" (rtos y1d5 2 2 ))
	(set_tile "d6" (rtos y1d6 2 2 ))
	(set_tile "d7" (rtos y1d7 2 2 ))
	(set_tile "d8" (rtos y1d8 2 2 ))
  (mode_tile "d0" 2);设置d0为焦点
	(action_tile "cancel" "(getdata1)(done_dialog 0)") ;取消
  (action_tile "accept"     "(getdata1)(done_dialog 1)") ;确认
	(action_tile "help" "(getdata1)(done_dialog 2)") ;帮助
	(action_tile "EL1" "(getdata1)(done_dialog 3)") ;帮助
  (setq re (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= re 0) ;取消
					(progn
						(prompt"\n 用户取消绘制图纸！")))
		((= re 2);帮助
			(progn
				(alert "1.圆弯头展开按照中径展开计算，展开精度与CAM保持一致，96等分展开；
2.展开形式整体和单段同CAM,引弧会将直段部分衔接在一起，便于生产制作，一般适用于口径小于等于350的弯头；
3.程序会根据选择的分段数及角度，综合判断分段合不合理，如果不合理，会出现文字提示；
4.所有的展开会自动刻线,自动标序号，同时对上下伸量处标注尺寸，便于检查图纸尺寸！
")	
			))	
		
		((= re 1);确认
			(progn
				;这里填充绘制图形的代码
				(setq pt0 (getpoint"请选择图形插入点"))
				(y1 pt0)
				
			))
	((= re 3);确认
				(test1))
		
	)	
	
	(h-save1  '(y1d0 y1d1 y1d2 y1d3 y1d4 y1d5 y1D6 y1d7 y1d8 ) "y1");储存数据到注册表
	(setvar "osmode" 16383)  ;打开对象捕捉状态
  (command "._undo" "_end")
	(princ)
)
;递进文字

(defun c:fg1( / )
  (vl-load-com)
  
  ; 第一步：选择序号图层上的序号文字
  (princ "\n请框选序号图层上的序号文字: ")
  (setq seq_ss (ssget '((0 . "TEXT,MTEXT") (8 . "序号图层"))))
  (if (not seq_ss)
    (progn
      (princ "\n未选择任何序号文字。")
      (princ)
      (exit)
    )
  )
  
  ; 遍历所有序号文字
  (repeat (setq i (sslength seq_ss))
    (setq seq_ent (ssname seq_ss (setq i (1- i))))
    (setq seq_obj (vlax-ename->vla-object seq_ent))
    (setq seq_str (vla-get-TextString seq_obj))
    
    ; 检查文字是否以"序号"开头且后面跟着数字
    (if (and (>= (strlen seq_str) 5)
             (wcmatch seq_str "序号#*")
             (setq seq_num (atoi (substr seq_str 5))))
      (progn
        ; 获取序号文字的插入点
        (setq seq_pt (vlax-get seq_obj 'InsertionPoint))
        (setq seq_pt (list (car seq_pt) (cadr seq_pt))) ; 只取X,Y坐标
        
        ; 计算修改范围（向左、右各延伸4000mm，向下延伸7400mm）
        (setq min_pt (list (- (car seq_pt) 4000.0) (- (cadr seq_pt) 7400.0)))
        (setq max_pt (list (+ (car seq_pt) 4000.0) (cadr seq_pt)))
        
        ; 在选择范围内查找需要修改的文字
        (setq mod_ss (ssget "_C" min_pt max_pt '((0 . "TEXT,MTEXT"))))
        
        (if mod_ss
          (progn
            ; 遍历范围内的所有文字对象
            (repeat (setq j (sslength mod_ss))
              (setq mod_ent (ssname mod_ss (setq j (1- j))))
              (setq mod_obj (vlax-ename->vla-object mod_ent))
              (setq mod_str (vla-get-TextString mod_obj))
              (setq len (strlen mod_str))
              (setq pos (vl-string-search "/" mod_str))
              
              ; 检查是否包含"/"且前面有数字
              (if (and pos (> pos 0))
                (progn
                  (setq end_index (1- pos))
                  (setq start_index end_index)
                  
                  ; 向前查找数字的开始位置
                  (while (and (>= start_index 0)
                              (<= (ascii "0") (ascii (substr mod_str (1+ start_index) 1)) (ascii "9")))
                    (setq start_index (1- start_index))
                  )
                  (setq start_index (1+ start_index))
                  
                  (if (<= start_index end_index)
                    (progn
                      ; 构建新的文字字符串
                      (setq part1 (if (> start_index 0) (substr mod_str 1 start_index) ""))
                      (setq start3 (+ end_index 2))
                      (setq part3 (if (<= start3 len) (substr mod_str start3) ""))
                      
                      ; 用序号数字替换原来的数字
                      (vla-put-TextString mod_obj (strcat part1 (itoa seq_num) part3))
                    )
                  )
                )
              )
            )
            (princ (strcat "\n序号" (itoa seq_num) "处理了 " (itoa (sslength mod_ss)) " 个文本对象。"))
          )
          (princ (strcat "\n序号" (itoa seq_num) "范围内未找到可修改的文本对象。"))
        )
      )
      (princ (strcat "\n跳过无效的序号文字: " seq_str))
    )
  )
  (princ "\n所有序号处理完成。")
  (princ)
)
(defun c:fg( / ss i ent obj str len pos end_index start_index numstr num newnum part1 part3 start3)
  (vl-load-com)
  (setq ss (ssget '((0 . "TEXT,MTEXT"))))
  (if ss
    (progn
      (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))))
        (setq obj (vlax-ename->vla-object ent))
        (setq str (vla-get-TextString obj))
        (setq len (strlen str))
        (setq pos (vl-string-search "/" str))
        (if (and pos (> pos 0))
          (progn
            (setq end_index (1- pos))
            (setq start_index end_index)
            (while (and (>= start_index 0)
                        (<= (ascii "0") (ascii (substr str (1+ start_index) 1)) (ascii "9")))
              (setq start_index (1- start_index))
            )
            (setq start_index (1+ start_index))
            (if (<= start_index end_index)
              (progn
                (setq numstr (substr str (1+ start_index) (1+ (- end_index start_index))))
                (setq num (atoi numstr))
                (setq newnum (itoa (1+ num)))
                (setq part1 (if (> start_index 0) (substr str 1 start_index) ""))
                (setq start3 (+ end_index 2))
                (setq part3 (if (<= start3 len) (substr str start3) ""))
                (vla-put-TextString obj (strcat part1 newnum part3))
              )
            )
          )
        )
      )
      (princ (strcat "\n成功处理了 " (itoa (sslength ss)) " 个文本对象。"))
    )
    (princ "\n未选择任何文本对象。")
  )
  (princ)
)

(h-check-version "1.1" 
 "                                     小辉插件程序更新到版本 1.1啦！\n\n更新内容： 
一、     off   关闭命令优化
 更新：不存关闭所有文档->不存关闭其他文档（当前活动文档除外）
            c3  直管命令优化
 更新： 新增刻线命令可以调整刻线长度
           c4  变径命令优化
1、处理当宽偏移和深偏移为负值时可能产生料片重叠的问题。
2、修复辅助视图无虚线判断实体位置的问题。
c7s命令优化
1.新增刻线长度调整选项（此项设置只针对直管，不针对变径与马口部分）
2.修复序号不连贯的问题（马口不再以口径作为编号，统一填充为序号）
3.修复长度低于3900分料从中间一刀切的问题（重新优化了低于3900的分料参数,）目前底平侧平分割线可能不到边，需要自己再手动延伸一下。
4.取消辅助视图与排版视图（好像基本用不到，还会增加卡顿，删了）
5.新增变径形式选项，目前有底平中变/底平侧平两个选项（底平侧平可带出三个变径料片）
6.新增变径长度选项，变径长度不局限于350，可以任意设置(注意不扣尺，350就输350即可）
---------------------------------------------------------------------------------

DTE 导出领料单命令优化
修复识别欧标和美标  新增当宽度不同插入分割线  新增对话框模式

FW 生成尾料命令优化
修复共边会产生错误尾料/修复尾料识别不全/优化进度条
       新增命令：编号递进
       程序内容：比如1/3 1/4 z1/3 z1/4 ->2/3 2/4 z2/3 z2/4
       快捷键：fg
      新增命令：自动调整序号（需要使用我的相关制图模板，就是一个框上面有标注序号1~n的）
      程序内容：自动检索 序号x 下方6000mm,左右4000mm,搜索相关序号，自动更新为序号x的序号
      举例：序号10 下面有个弯头展开图， 弯头展开图的序号是2/1 2/2 2/3 2/4，使用命令后会更新10/1 10/2 10/3 10/4
      快捷键：fg1         
       新增命令：圆弯头一键展开
       功能：展开精度，192等分，比CAM精度高一倍，展开样式共三种：整体/单段/引弧
       快捷键：Y1  
       新增命令：批量合并DXF文件
       功能：合并文档中的所有DXF文件（从CAMduct导出文件过多时，可以使用此命令，不用一个一个打开了）
       快捷键：XCO         
       新增命令：批量合并DWG文件
?      功能：合并文档中的所有DWG文件
      新增命令：排前检查
      功能：封闭检查/文字查重/编号确认/调整文字位置/生成新的待排版图
      快捷键：jc
     新增命令：自动排版
     功能：对板材进行简单自动排版，红色编号，青色数量，黄色刻线
     快捷键：pb
    新增命令：排版调整
    功能：调整排版后的板材间隙，同排版软件
    快捷键：tz
上述更新已自动完成更新，直接使用即可，快去看看把！
")
